0

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>

9
  • What is the grid bound to? Commented Nov 21, 2023 at 13:26
  • You shouldn't need to use a CurrencyManager directly. Bind via a BindingSource and then access everything related to data binding through it, including the SuspendBinding method, should you actually need it. Commented Nov 21, 2023 at 13:27
  • @jmcilhinney, I do not understand your recommendation Commented Nov 21, 2023 at 13:54
  • 1
    As for the issue, get rid of all that code. You have a DataTable bound to a BindingSource. Just set the Filter property of the BindingSource appropriately and that will handle the filtering. Commented Nov 21, 2023 at 14:11
  • 1
    You're wrong but I'm not gaining anything by arguing the point so I'm out. Commented Nov 21, 2023 at 16:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.