C#, Forms, DataGridView. Unexpected Visible behaviour

44 Views Asked by At

I working on application with DataGridView.
It contains several tabs, each tab includes a DataGridView of some parameters. I need implement Admin and User modes, where each grid table should hide some rows according to the mode.
I have a problem with the hiding: on some tabs the hiding work perfect on other doesn't work absolutely.
I did some tests: hid all rows of problematic grid, printed Visible values after delay.
usedgrid.CurrentCell = null.
I didn't found any mistake that point to the reason of the problem. I use the same method for all:

private void HideParameter(DataGridView grid, string ParamName)
{
    CurrencyManager CM = (CurrencyManager)BindingContext[grid.DataSource];
    CM.SuspendBinding();
    for (int i = 0; i < grid.Rows.Count; i++)
    {
        string Val = grid.Rows[i].Cells[0].Value.ToString();
        if (Val.Contains(ParamName))
        {
            //grid.CurrentCell = null;
            grid.Rows[i].Visible = false;
        }
    }
    CM.ResumeBinding();
}

Grid binding:

void BindGridWithDataSource(DataTable dt, DataGridView grid)
{
  BindingSource bs = new BindingSource();
  bs.DataSource = dt;
  grid.DataSource = bs;
}

<brPicture of the tabs>

0

There are 0 best solutions below