Hide selected row in DataGridView

  • Thread starter Thread starter osmarjunior
  • Start date Start date
O

osmarjunior

When I try to make the current row invisible, I got an error.
I put a checbox that turns some rows visible/invisible.
Then if the selected row is turning to invisible, it raises an
exception.

My code:

foreach (DataGridViewRow row in myGrid.Rows)
if ((bool)row.Cells[0].Value.Equals(false))
row.Visible = checkbox.Checked;

What's wrong in that???

Thanx....

Junior.
 
osmarjunior said:
When I try to make the current row invisible, I got an error.
I put a checbox that turns some rows visible/invisible.
Then if the selected row is turning to invisible, it raises an
exception.

My code:

foreach (DataGridViewRow row in myGrid.Rows)
if ((bool)row.Cells[0].Value.Equals(false))
row.Visible = checkbox.Checked;

What's wrong in that???

Thanx....

Junior.

Um, What's the exception?

You may need to change the current row to the next/previous row before
you hide it.

Chris
 
I didn't posted the exception, 'cause I just got it in portuguese.
I've tried to invoke the method ClearSelection() before the foreach
loop.
Without success... :(

myGrid.ClearSelection();

foreach (DataGridViewRow row in myGrid.Rows)
if ((bool)row.Cells[0].Value.Equals(false))
row.Visible = checkbox.Checked;

Your solution maybe can be a problem if I have one single row in
DataGridView.
Then if I try to turn it to invisible??? Because, in this case, there
is no next or previous rows to select...

Thanx...

Junior.
 
Junior,

Instead of indicating if the row is visible or not, why not bind the
DataGridView to a dataview which is filtered on the column that is storing
the true/false value?

Hope this helps.
 
Back
Top