0

so i'm having the issue of getting a null reference when checking the checkbox column on my data grid, though this only occurs when the checkboxes are outside of view at startup of the program. E.g. checks until the first 20 visible rows are fine, but not there after.

Here's my iteration code:

My item source is a List of Type which i need to instantiate if the row is checked. 'permissions' is a PermissionSet which I need to populate.

        foreach (Type t in dataGridPerms.ItemsSource)
        { 
            try
            {
                bool? check = ((CheckBox)AllowColumn.GetCellContent(t)).IsChecked; //offending line
                if (check == true)
                {
                    Object o = Activator.CreateInstance(t, PermissionState.Unrestricted);
                    permissions.AddPermission((IPermission)o);
                }
            }
            catch(Exception e)
            {
                continue;
            }
        }

I have searched online but found no solid help, though I have read bits on data binding which may be of use but I don't really have an idea on where to start if that is the solution as i am new to WPF.

Many thanks for any help :)

Edit:

The duplicate question/answer provided is a very stripped down version of my issue. My issues relates closely to WPF and it's constructs.

  • 3
    You seem to be using WPF with Windows Forms knowledge. Don't do that. It will lead you into a world of pain and you will never know how cool WPF can be. Please start by reading a good basic book or tutorial. WPF is not something you can learn by doing it the Windows Forms way. – nvoigt Feb 10 '15 at 12:26
  • Either `AllowColumn` or the value returned from `GetCellContent(t)` is null. We can't tell why. Use your debugger. – Clemens Feb 10 '15 at 15:07

0 Answers0