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.
How you are getting a collection of CheckBoxHeaderCell.
In other words I need the code that you are initializing the headerCells variable.
Please provide the information I requeted, so I may be a further assistence.
I was not able to recreate your scenario from the code you provided.
If you can provide me a sample I would be able quicker to help you.
In other case I'm trying to build your sample and at the moment I don't know what CheckBoxHeaderCellControl is.
Here is a topic that is covering checkboxes in header:
http://ko.infragistics.com/community/blogs/devin_rader/archive/2011/04/29/adding-a-select-all-checkbox-to-a-xamgrid-checkboxcolumn-header.aspx
The collection of CheckBoxHeaderCell is being generated as a HeaderCell for the checkbox column we are having for the grid.
So when we are grouping records a new headercell is getting created when we are expanding grouped records. Below is the overridden method of checkbox column through which we are creating new CheckBoxheaderCell and adding it to collection. In the below code the variable CheckOnlySingleRow only specifies whether we want multiple selection in grid or not.
protected override CellBase GenerateHeaderCell(RowBase row) { if (!CheckOnlySingleRow) { CheckBoxHeaderCell headerCell = new CheckBoxHeaderCell(row, this); headerCells.Add(headerCell); return headerCell; } return base.GenerateHeaderCell(row); }
Also i am not sure but the issue could be that we are adding headercells to the collection but when we are removing grouping the headercells added to the collection are not getting removed. Is there any method available for the same?
Hope this helps.