posted 4/1/2009 by Vivek Thakur
In your windows forms applicatons, if you want to hide/make inivisible a row of the DataGridView control at runtime, you would assume that this line will do the trick:
for (int i = 0; i < dgridView.Rows.Count; i++) { if(someCondition) dgridView.Rows[i].Visible = false; }
But the moment you do this, you will get this error:Row associated with the currency manager's position cannot be made invisible
The reason for this particular error is that you cannot make modifications to a row at runtime which is bound to datasource, unless you suspned the binding on all rows using CurrencyManager object like:
cManager.SuspendBinding();dgridView.Rows[i].Visible = false;
Or, you can also do this:
dgridView.CurrentCell = null;dgridView.Rows[i].Visible = false;
Here we are setting the current cell to null and then hiding the row.
Note: if you are using sorting, then you would need to hide the hidden rows again because after sorting hidden rows would show up again unless you remove them from the binding source itself.
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18