Unable To set row visible false of a datagridview
Example
foreach (DataGridViewRow rw in dataGridView1.Rows)
{
if (rw.Cells[14].Value.ToString() == "") // this Cell have a TEXT,
{
CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dataGridView1.DataSource];
currencyManager1.SuspendBinding();
rw.Visible = false;
currencyManager1.ResumeBinding();
}
}
this show only the row that have in the cell index 14, if this is blank or empty the whole row not show
After searching a lot, I got the solution
CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];
currencyManager1.SuspendBinding();
MyGrid.Rows[5].Visible = false;
currencyManager1.ResumeBinding();
Cannot set yourDataGridView row visible property to false when current row index Will encounter such error if trying to hide current cell
soulution :
when yourDataGridView Data source is not null :
CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[yourDataGridView.DataSource];
currencyManager1.SuspendBinding();
yourDataGridView.Rows[Target Index].Visible = false;
currencyManager1.ResumeBinding();
when yourDataGridView Data source is null :
yourDataGridView.CurrentCell = null;
yourDataGridView.Rows[Target Index].Visible = false;