This is a migrated thread and some comments may be shown as answers.

why did not foreach GroupDescriptors,upgrade offical version Q3

5 Answers 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jerome
Top achievements
Rank 1
jerome asked on 15 Nov 2010, 08:58 AM
hi,
this is ok in version 924 ,the code as follows:
List<string> groupColumns = new List<string>();
 
              foreach (GroupDescriptor group in dataGrid.GroupDescriptors)
              {
                  if (!string.IsNullOrEmpty(columnaList))
                  {
                      columnaList += "," + group.Member;
                  }
                  else
                  {
                      columnaList += group.Member;
                  }
                  groupColumns.Add(group.Member);
              }


upgraded q3,  throw exception message: 
Unable to cast object of type 'Telerik.Windows.Controls.GridView.ColumnGroupDescriptor' to type 'Telerik.Windows.Data.GroupDescriptor'.

since 924 is ok.
Do not understand


we have other code for it. load GroupDescriptor for save data.

GroupDescriptor descriptor = new GroupDescriptor();
 if (pair.Key == "SecID")
 {
     CountFunction countFunction = new CountFunction { Caption = "Count:" };
     holdingColumn.FooterTextAlignment = TextAlignment.Left;
 
     holdingColumn.AggregateFunctions.Add(countFunction);
     descriptor.AggregateFunctions.Add(countFunction);
 }

then  so  to do..    add  descriptor  to datagrid

if (groupByData.ContainsKey(SelectedTabIndexer))
            {
                if (groupByData[SelectedTabIndexer].Contains(columnName))
                {
                    descriptor.Member = columnName;
                    descriptor.DisplayContent = displaycontent;
                    SelectedDataGrid.GroupDescriptors.Add(descriptor);
                }
            }

OK,  SelectedDataGrid.GroupDescriptors.Count() > 0 
if changed code use ColumnGroupDescriptor  :

foreach (ColumnGroupDescriptor group in dataGrid.GroupDescriptors)
{
    if (!string.IsNullOrEmpty(columnaList))
    {
        columnaList += "," + group.Column.UniqueName;
    }
    else
    {
        columnaList += group.Column.UniqueName;
    }
    groupColumns.Add(group.Column.UniqueName);
}
 
throw exception message:
Unable to cast object of type 'Telerik.Windows.Data.GroupDescriptor' to type 'Telerik.Windows.Controls.GridView.ColumnGroupDescriptor'.

why ?  both  Telerik.Windows.Data.GroupDescriptor and  Telerik.Windows.Controls.GridView.ColumnGroupDescriptor  did not foreach?

any question?

thanks

5 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 15 Nov 2010, 12:55 PM
Hello jerome,

 This happens because there appear to be both GroupDescriptors and ColumnGroupDescriptors in the GroupDescriptors collection of RadGridView. You need to use the OfType<> extension method (found in the System.Linq namespace) in order to filter the GroupDescriptors collection to only GroupDescriptors or ColumnGroupDescriptors.

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
jerome
Top achievements
Rank 1
answered on 16 Nov 2010, 02:12 AM
oh,

Thank you very much
0
Gaurang
Top achievements
Rank 1
answered on 29 Mar 2011, 08:30 AM
Hi I think I have same problem with my code when I updated new dll of telrik now it is not working please reply me.
My code is here

sortOptions.Add(gridView.GroupDescriptors);

 

 

 

 

public void Add(GroupDescriptorCollection groupDescriptorCollection)

 

 

{

 

 

 

foreach (GroupDescriptor groupDescriptor in groupDescriptorCollection) //gives error here

 

{

if(groupDescriptor.SortDirection == ListSortDirection.Ascending)

 

{

 

this.SortCriteriaList.Add(new SortCriteria(groupDescriptor.Member, SortOrder.Ascending));
}

 

 

 

 

else if (groupDescriptor.SortDirection == ListSortDirection.Descending)
{
this.SortCriteriaList.Add(new SortCriteria(groupDescriptor.Member, SortOrder.Descending));

 

 

}

 

 

 

 

}

}

it gives me error like
Unable to cast object of type 'Telerik.Windows.Controls.GridView.ColumnGroupDescriptor' to type 'Telerik.Windows.Data.GroupDescriptor'.

Gaurang Vaishnav

0
jerome
Top achievements
Rank 1
answered on 30 Mar 2011, 02:11 AM
you can use code like  below:

foreach (ColumnGroupDescriptor group in dataGrid.GroupDescriptors.OfType<ColumnGroupDescriptor>())
            
foreach (GroupDescriptor group in dataGrid.GroupDescriptors.OfType<GroupDescriptor>())


0
Gaurang
Top achievements
Rank 1
answered on 30 Mar 2011, 11:28 AM
Thanks you for your reply now my problem is solved.

I tried this
foreach (GroupDescriptor group in dataGrid.GroupDescriptors.OfType<GroupDescriptor>)

So I was getting error on foreach because I missed to place () {braket} at end.
foreach (GroupDescriptor group in dataGrid.GroupDescriptors.OfType<GroupDescriptor>())

Gaurang Vaishnav
Tags
GridView
Asked by
jerome
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
jerome
Top achievements
Rank 1
Gaurang
Top achievements
Rank 1
Share this question
or