Skip to content

DataGridView Filter #1032

Description

@itg-assistant

Angelo Bordonaro asked 2017-08-18 15:57:31 UTC

Hi,

I have a datagridview binded with a datatable and a datatime column.
Here is the code used.

Imports System.Data
Imports Wisej.Web
Public Class Window1
Private dgvBindingSource As Wisej.Web.BindingSource = New Wisej.Web.BindingSource
Private Sub Window1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myTable As DataTable
Dim myNewRow As DataRow
' Create a new DataTable.
myTable = New DataTable("My Table")
' Create DataColumn objects of data types.
Dim colDateTime As DataColumn = New DataColumn("DateTimeCol")
colDateTime.DataType = System.Type.GetType("System.DateTime")
myTable.Columns.Add(colDateTime)
' Populate one row with values.
myNewRow = myTable.NewRow()
myNewRow("DateTimeCol") = CDate("11/08/17")
myTable.Rows.Add(myNewRow)
myNewRow = myTable.NewRow()
myNewRow("DateTimeCol") = CDate("24/07/17")
myTable.Rows.Add(myNewRow)
myNewRow = myTable.NewRow()
myNewRow("DateTimeCol") = CDate("19/07/17")
myTable.Rows.Add(myNewRow)
Dim dgvDataView As DataView = myTable.DefaultView
dgvBindingSource.DataSource = dgvDataView
DataGridView1.DataSource = dgvBindingSource
DataGridView1.Columns("DateTimeCol").DefaultCellStyle.Format = "dd-MM-yy"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dgvBindingSource.Filter = "[DateTimeCol]=#2017-07-24#"
End Sub
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Dim a As String = e.Value.ToString
End Sub

Explain the problem.
If I select the cell of the second line and apply the filter, I have an error.
But if you comment the line in the cellformatting event the filter works.
I can not understand the reason.
I attach the sample project
Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is broken or behaving unexpectedly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions