2
Answers

Silverlight:DataGrid-Exception - Index must be within bounds

Sanal Rajan

Sanal Rajan

7y
303
1

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<string> RepcolumnName = new ObservableCollection<string>(); 
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"; } 
else if (index == 2) {  bindCol = "Name"; } 
 templateColumn.HeaderStyle = LayoutRoot.Resources["headerStyle"] as Style; 
StringBuilder CellTemp = new StringBuilder(); 
CellTemp.Append("<DataTemplate "); 
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("<Grid>"); CellTemp.Append("<TextBlock "); 
CellTemp.Append("Text ='{Binding Path=" + bindCol + "}'  Style='{StaticResource ContentTextStyle}' IsHitTestVisible='False' ");
 CellTemp.Append("Margin='4'/>"); 
CellTemp.Append("</Grid>"); 
CellTemp.Append("</DataTemplate>");  
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"));
} 


 
Answers (2)
0
Bikesh Srivastava

Bikesh Srivastava

NA 19.8k 835k 8y
can you share your complete code..
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 8y
Follow below link that may help you:
http://stackoverflow.com/questions/14157072/using-renderactionactionname-values-in-mvc4-issue
http://devproconnections.com/development/how-use-aspnet-mvc-render-action-helpers