Hello,
Iterating through the rows collection of the RadGridView in order to check the cell value in the GridViewCheckBoxColumn is the right approach to achieve this. As to the System.NullReferenceException error that you get, could you please make sure that you have a column with the same name in your grid. The checkbox column's data source must contain the respective values as well. I prepared an example for your reference:
public RadForm1()
{
InitializeComponent();
DataTable dt = new DataTable();
dt.Columns.Add("PersonID", typeof(int));
dt.Columns.Add("LastName", typeof(string));
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("IsChecked", typeof(bool));
dt.Rows.Add(1, "Davolio", "Nancy", true);
dt.Rows.Add(2, "Fuller", "Andrew", false);
dt.Rows.Add(3, "Leverling", "Janet", true);
dt.Rows.Add(4, "Dodsworth", "Anne", false);
dt.Rows.Add(5, "Wolfeschlegel", "Hubert", true);
dt.Rows.Add(6, "Woldorf", "Hubert", true);
dt.Rows.Add(7, "Addams", "Mary", true);
this.radGridView1.DataSource = dt;
GridViewCheckBoxColumn checkBoxColumn = this.radGridView1.Columns["IsChecked"] as GridViewCheckBoxColumn;
IList<GridViewRowInfo> gridRows = new List<GridViewRowInfo>();
foreach (GridViewRowInfo rowInfo in radGridView1.ChildRows)
{
bool isChecked = (bool)rowInfo.Cells["IsChecked"].Value;
if (isChecked == true)
{
gridRows.Add(rowInfo);
}
}
Console.WriteLine(gridRows);
}
Note that GridViewCheckBoxColumn has the EditMode property that controls when the value of the editor will be submitted to the cell. By default, the current behavior is kept (OnValidate) and the value will be submitted only when the current cell changes or the grid loses focus. The new value (OnValueChange) will submit the value immediately after the editor value changes.
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Nadya
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.