Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Exception by group by column
posted

Hi,

I have a grid with 3 column e.g. select, person and old .

I can disable the cell "select" Grid1.Rows[0].Cells["Select"].Activation = Activation.Disabled

this work fine.

And now  if I group the Grid by the column person , there is exception because Grid1.Rows[0].Cells is null.

How can I fix this bug?

Thanks

Habib

  • 69832
    Offline posted

    Grid1.Rows[n].Cells cannot possibly return null because the Cells property automatically creates an instance and returns it. If you are accessing Grid1.Rows[0].Cells at a point when there are no rows, that would cause an IndexOutOfRangeException; the way to remedy this is to check Grid1.Rows.Count before accessing any members. Generally speaking, the way to prevent a null reference exception is to check for null before accessing any object that can be null.