Silverlight:DataGrid-Exception - Index must be within the bounds of the List. Parameter name: index after grouping using PagedCollectionView :
When executing this code at first time it is working. second time onwards throwing exception " Index must be within the bounds of the List" . If i remove " itemListView.GroupDescriptions.Add " data is showing in the grid. Without removing this line how to solve this..
Codes are here....
ObservableCollection RepcolumnName = new ObservableCollection (); RepcolumnName.Add(ResourceFile.SrNoLevel); RepcolumnName.Add(ResourceFile.EmpCodeLabel); RepcolumnName.Add(ResourceFile.EmployeeNameLabel); Binding binding = new Binding(); int index = 0; string bindCol = ""; foreach (var header in RepcolumnName) { DataGridTemplateColumn templateColumn = new DataGridTemplateColumn(); templateColumn.Header = header; if (index == 0) { bindCol = "sNo"; } else if (index == 1) { bindCol = "Empno"; }
else if (index == 2) { bindCol = "Name"; }
templateColumn.HeaderStyle = LayoutRoot.Resources["headerStyle"] as Style;
StringBuilder CellTemp = new StringBuilder();
CellTemp.Append(");
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
CellTemp.Append("2006/xaml/presentation' ");
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
CellTemp.Append("xmlns:local = 'clr-namespace:System.Windows.Controls");
CellTemp.Append(";assembly=System.Windows.Controls.Toolkit'>");
CellTemp.Append("" ); CellTemp.Append(");
CellTemp.Append("Text ='{Binding Path=" + bindCol + "}' Style='{StaticResource ContentTextStyle}' IsHitTestVisible='False' ");
CellTemp.Append("Margin='4'/>");
CellTemp.Append("");
CellTemp.Append("");
templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString());
DgvEmpData.Columns.Add(templateColumn);
index++; }
PagedCollectionView itemListView = new PagedCollectionView(FinalEmpList);
DgvEmpData.ItemsSource = itemListView;
if (itemListView.CanGroup == true) {
itemListView.GroupDescriptions.Add(new PropertyGroupDescription("DeptName"));
}

Rajkiran SwainPosted Jun 19, 2017, 6:08 AM
Sanal RajanPosted Jun 20, 2017, 4:06 AM