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....
C#
ObservableCollection RepcolumnName = new ObservableCollection();C#
RepcolumnName.Add(ResourceFile.SrNoLevel);C#
RepcolumnName.Add(ResourceFile.EmpCodeLabel);C#
RepcolumnName.Add(ResourceFile.EmployeeNameLabel);C#
Binding binding = new Binding();C#
int index = 0; string bindCol = "";C#
foreach (var header in RepcolumnName)C#
{C#
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();C#
templateColumn.Header = header;C#
if (index == 0)C#
{ bindCol = "sNo"; }C#
else if (index == 1) { bindCol = "Empno"; }C#
else if (index == 2) { bindCol = "Name"; }C#
templateColumn.HeaderStyle = LayoutRoot.Resources["headerStyle"] as Style;C#
StringBuilder CellTemp = new StringBuilder();C#
CellTemp.Append(");C#
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");C#
CellTemp.Append("2006/xaml/presentation' ");C#
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");C#
CellTemp.Append("xmlns:local = 'clr-namespace:System.Windows.Controls");C#
CellTemp.Append(";assembly=System.Windows.Controls.Toolkit'>");C#
CellTemp.Append(""); CellTemp.Append(");C#
CellTemp.Append("Text ='{Binding Path=" + bindCol + "}' Style='{StaticResource ContentTextStyle}' IsHitTestVisible='False' ");C#
CellTemp.Append("Margin='4'/>");C#
CellTemp.Append("");C#
CellTemp.Append("");C#
templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString());C#
DgvEmpData.Columns.Add(templateColumn);C#
index++; }C#
PagedCollectionView itemListView = new PagedCollectionView(FinalEmpList);C#
DgvEmpData.ItemsSource = itemListView;C#
if (itemListView.CanGroup == true) {C#
itemListView.GroupDescriptions.Add(new PropertyGroupDescription("DeptName"));C#
}C#
C#


Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 19, 2017, 2:08 AM EDT
Sanal Rajan139 reputationPosted Jun 20, 2017, 12:06 AM EDT