0

I'm stuck with this code. I want to hide some rows so I wrote this line first and its work fine

    foreach (DataGridViewRow row in dataGridView1.Rows)
      {
        if ((string)row.Cells[11].Value != (string)row.Cells[12].Value)
          {
             row.DefaultCellStyle.BackColor = Color.Red;
          }
        else
          {
            row.DefaultCellStyle.BackColor = Color.Green;
          }
      }

I want now to hide row instead of green color so I changed

row.DefaultCellStyle.BackColor = Color.Green;

with

row.Visible = false;

but i get an error with that.

Karthik Ganesan
  • 4,142
  • 2
  • 26
  • 42

2 Answers2

0

You should cast the row to DataGridViewBand as documented here

DataGridViewBand band = row;
band.Visible = false;
Peter Schneider
  • 2,879
  • 1
  • 14
  • 17
  • Thank you but i'm still have the same error -- Can not make invisible the line associated with the map manager position. -- i don't know what's this error mean – Raouf Bessghaier Nov 14 '19 at 15:55
0

I'm trying this method and this time row become invisible as i wanted but after that an error happen

                    CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dataGridView1.DataSource];
                currencyManager1.SuspendBinding();
                dataGridView1.CurrentCell = null;
                row.Visible = false;
                dataGridView1.Refresh();

error :

Could not make invisible the new line not validated