I use a datagrid with rows columns with date format.
This is the datagrid creation code
dg_datos.Columns.Add("tarea", "Tarea")
dg_datos.Columns.Add("horas", "Horas")
dg_datos.Columns.Add("descripcion", "Descripcion")
dg_datos.Columns.Add("fecha", "Fecha")
dg_datos.Columns("fecha").DefaultCellStyle.Format = "dd/MM/yyyy"
dg_datos.Rows.Add("Ada Lovelace", "1", "desc.1", "10/11/2002")
dg_datos.Rows.Add("Rafael Nadal", "1.4", "desc.2", "11/11/1822")
dg_datos.Rows.Add("Lewis Hamilton", "0.4", "desc.3", "19/11/1978")
dg_datos.Rows.Add("Charles Leclerc", "5", "desc.4", "02/01/1992")
dg_datos.Rows.Add("HOLA HOLA", "5", "desc.5", "20/04/2022 0:00:00")
Dim table As New DataTable
BindingSource1.DataSource = table
dg_datos.DataSource = BindingSource1
Private Sub Calendario_DateSelected(sender As Object, e As DateRangeEventArgs) Handles calendario.DateSelected
BindingSource1.Filter = String.Format("fecha = #{0:M/dd/yyyy}#", calendario.SelectionStart)
End Sub
I dont know why this dont work
CodePudding user response:
I decided to just post an answer to avoid further agony, although there's no guarantee that you won't do things not in the answer. Anyway, you should be binding the data something like this:
Dim table As New DataTable
Using adapter As New SqlDataAdapter(query, connectionString)
adapter.Fill(table)
End Using
BindingSource1.DataSource = table
DataGridView1.DataSource = BindingSource1
You then filter the data exactly as I have repeatedly told you in the comments:
Private Sub Calendario_DateSelected(sender As Object, e As DateRangeEventArgs) Handles calendario.DateSelected
BindingSource1.Filter = String.Format("fecha = #{0:M/dd/yyyy}#", calendario.SelectionStart)
End Sub