Hi,
I have been using Xamgrid in my application and recently we were adding support for multi level checkbox selection for the items in the grid.
Regarding the same we needed to iterate our HeaderCell to remove the checkbox state.
But when i am iterating the HeaderCell in our grid i keep on getting exception in the code below.
foreach (CheckBoxHeaderCell headerCell in headerCells) { if (headerCell != null) { bool? state = null; int checkedRowsCount = 0; if (headerCell.Row.Manager.Rows != null) { foreach (Row row in headerCell.Row.Manager.Rows) { if (row.Data is ICheckable && (row.Data as ICheckable).IsChecked) { checkedRowsCount++; } } }
I get the exception on the line "foreach(Row row in headerCell.Row.Manager.Rows)"
The exception i get is "Object reference not set to an instance of object".
Below is the stack trace for the exception please let me know if you could suggest something regarding what could be wrong and why xamgrid is throwing the exception.
at Infragistics.Controls.Grids.RowsManager.SetupDataManager()
at Infragistics.Controls.Grids.RowsManager.EnsureDataManager()
at Infragistics.Controls.Grids.RowsManager.get_DataManager()
at Infragistics.Controls.Grids.RowsManager.get_DataCount()
at Infragistics.Controls.Grids.RowsManager.Infragistics.IProvideDataItems<Infragistics.Controls.Grids.Row>.get_DataCount()
at Infragistics.Collections.BindableItemCollection`1.GetCount()
at Infragistics.Collections.CollectionBase`1.get_Count()
at Infragistics.Collections.CollectionBaseEnumerator`1.System.Collections.IEnumerator.MoveNext()
Hi Vidhi,
I want to help you with your case.
For that I'll need some more information.
If you can send me a sample that I can reproduce the issue.
If that's not possible some explanation of what headerCells collection contains and what CheckBoxHeaderCell is would be helpful.
Thanks,
George
Hi George,
Thanks for the response.
I tried to create a sample application to reproduce the issue but due to large level of dependencies failed to do so :(.
I can provide you details regarding the collection and the scenario it is occurring in:
The issue is occurring when we are grouping records in the xamgrid on the base of two columns and then we remove the grouping.
Now in our grid we have Checkbox a column to select multiple records in the grid, and our headerCells we have a collection of all the HeaderCell which for the Checkbox column [as we can have multiple HeaderCell's when we are grouping the records].
After we have removed the grouping and we try to iterate all the headerCells in the above code we get the error as mentioned below.
CheckBoxHeaderCell is a class extended from HeaderCell and its deifinition follows below.
public class CheckBoxHeaderCell : HeaderCell { public CheckBoxHeaderCell(RowBase row, Column col) : base(row, col) { } protected override Type RecyclingElementType { get { return typeof(CheckBoxHeaderCellControl); } } protected override CellControlBase CreateInstanceOfRecyclingElement() { return new CheckBoxHeaderCellControl(); } public void SetCheckBoxState(bool? state) { var checkBoxCellControl = Control as CheckBoxHeaderCellControl; if (checkBoxCellControl != null) { checkBoxCellControl.SetCheckBoxState(state); } } }
Hope the above information helps you in providing some solution to the problem.