DataGridView Filter

0
0
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
  • You must to post comments
0
0

Hi Angelo,

I´ll check in more detail, but you can get around the exception if you change your code to

If (e.Value IsNot Nothing Then
Dim a As String = e.Value.ToString
End If

Best regards
Frank

  • You must to post comments
0
0

Thanks Frank,
At the moment I solved with your precious advice.
I look forward to further details.

My application, which I am translating from a WindowsForm, is quite complex (custom datgridview, custom event, etc) and I would not want to avoid other problems due to the bug.

  • You must to post comments
0
0

Hi Angelo,

we checked this in detail and here is what happens:

When you set the filter, it resets the rows and the data source sets the cell to -1/-1
causing the DataGridView to validate the current cell, but the data source is null.

It´s logged as WJ-8404, fixed and will be included in the next release.

Best regards
Frank

  • You must to post comments
0
0

Hi Angelo,

WJ-8404 is fixed in Wisej release 1.4.20

Best regards
Frank

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.