I have a Datagridview bound to a datatable. I'd like to hide or show a row depending on the value of a cell, for example if the cell value is "N" make the row visible else if it is "Y", hide the row.
The datacolumn is setup as:
New DataColumn With {.ColumnName = "Rec", .AllowDBNull = False, .DefaultValue = "N", .DataType = GetType(String)}
I have also handled the CellValueChanged event of the Datagridview as below:
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If CType(sender, DataGridView).Columns(e.ColumnIndex).HeaderText.Equals("Rec") Then
CType(sender, DataGridView).Rows(e.RowIndex).Visible = CType(sender, DataGridView).Item(e.ColumnIndex, e.RowIndex).Value.Equals("N")
End If
End Sub
But when I programmatically change the value to "Y" (and I can see the value has changed in the grid), the row is still visible. I also put a break inside the event handler and it is NOT fired! So the question, how do I hide a datagridviewrow when I change a cellvalue to "Y"?
EDIT
Just to add some more clarity to the problem at hand, this is how I programmatically update the grid's datasource:
CType(DataGridView1.DataSource, DataTable).Item("Rec") = "Y"
I can directly update the grid and therefore fire the cellvaluechanged event, however this throws the CurrencyManager error, and therefore having to suspend binding then resuming binding to the grid every time the cell value updates. That works but at a snail's pace for even a small dataset (even with double buffering implemented via reflection).
DataTable
. – FabioN
? – Fabio