By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,163 Members | 1,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,163 IT Pros & Developers. It's quick & easy.

Hide selected row in DataGridView

P: n/a
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.

Mar 31 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
osmarjunior wrote:
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
Mar 31 '06 #2

P: n/a
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.

Mar 31 '06 #3

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"osmarjunior" <os*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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.

Apr 1 '06 #4

P: n/a
Good sugestion. Thanx...

Apr 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.