Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridViewRow.Visible property set to False, but then visible after binding
 

DataGridViewRow.Visible property set to False, but then visible after binding

Greetings,

I have a DGV that is bound to a DataTable. I handle the DataGridView.RowsAdded() event, and in certain circumstances, I set the Visible property of some rows to false. It properly hides the row (I actually *never* see the row, because I'm doing this in the RowsAdded event). However, there's a strange occurence where if the hidden row is the 2nd to last row in the DGV, for example:

row0: Visible = true
row1: Visible = true
row2: Visible = false
row3: Visible = true

If I then remove the 4th row from the DataTablewhich is bound to the DGV, the 4th row (index 3) deletes as it should, but row2 is now visible!Why is the removal (and subsequent re-binding) of the DataTable row causing the Visible property to be true for rows that I've already set Visible to false? And moreover, how can I prevent this?

Thanks,
Rick
slikrik  Wednesday, September 09, 2009 10:50 PM
I've discovered some more details about this bug, so I'm hoping with this additional insight, someone will have an idea for me.

If I set a row's Visible property to false, it is hidden as I would expect. However, if the row beneath where the hidden row should be (so row3 in my original post) is selected -- meaning the entire row is selected -- and this row is deleted from the underlying DataTable (which subsequently deletes the row from the DataGridView), then the hidden row is suddenly visible again! It must be the row directly beneath where the hidden row exists, and IT MUST BE THE LAST ROW of the DataGridView. In other words, if row4 is deleted from the scenario below:

row0: Visible = true
row1: Visible = true
row2: Visible = false
row3: Visible = true
row4: Visible = true

so if row4 (the last row) is selected when it is removed, the bug does not occur. But in this scenario:

row0: Visible = true
row1: Visible = true
row2: Visible = false
row3: Visible = true

if row3 is selected when it is removed, the bug DOES occur (because it is the last row in the DGV).

Why is this occurring? Is this a "bug" or intended behavior of the DGV? Does anyone have any suggestions for a workaround?

Thanks,
Rick
slikrik  Thursday, September 10, 2009 6:29 PM

You can use google to search for other answers

Custom Search

More Threads

• last record changed not saving in dataset
• Item cannot be added to a read-only or fixed-size list
• Vertical DataGridView
• Losing values of Unbound Columns
• Databinding to a DateTimePicker control
• DatarowState not updating when value being updated via binded textbox.
• ComboBox does not update when DataSource is updated by BackgroundWorker
• TreeNode Tag Property
• InfoPath 2007 Rich Text Box Control: Not showing embedded images from webservice XHTML data
• Show text in text box based on selection from combo box