Hide selected row in DataGridView

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.
 
C

Chris

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
 
O

osmarjunior

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top