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

Never bind to DataTable.DefaultView?

5 Answers 695 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steffen
Top achievements
Rank 1
Veteran
Steffen asked on 18 Aug 2010, 04:13 PM
Hi,
I just spend the whole day to find out why my RadGridView is not working like I thought it should.
No matter where and how (xaml | c#) I put my GroupDescriptions and AggregateFunctions the GridView always showed a different behaviour and never did what I wanted it to do. Sometimes the grouping failed sometimes the aggregates failed and sometimes it worked after removing and adding the groups multiple times from code-behind. I finally took a telerik sample (http://www.telerik.com/community/forums/wpf/gridview/group-header-with-aggregated-functions.aspx) and changed it to use a DataTable instead of ObservableCollection ==> and suddenly the demo worked as weird as my application. In WPF you always have to bind to the DefaultView(or any other DataView) if you want a working TwoWay-Binding to a DataTable. Because I had no more idea what to try I just bound to the DataTable instead of DataTable.DefaultView ==> and everything started working as expected.

Are DataViews not supported anymore???

Best Regards
Steffen   

5 Answers, 1 is accepted

Sort by
0
Steffen
Top achievements
Rank 1
Veteran
answered on 19 Aug 2010, 09:01 AM
To reproduce the issue just take the example (http://www.telerik.com/community/forums/wpf/gridview/group-header-with-aggregated-functions.aspx). Then add a  GroupDescriptor in XAML:
<telerik:RadGridView.GroupDescriptors>
    <telerikData:GroupDescriptor Member="Country" SortDirection="Ascending"/>
</telerik:RadGridView.GroupDescriptors>
and change code behind like this:
public Window1()
        {
            InitializeComponent();
            //this.playersGrid.ItemsSource = Club.GetPlayers();
 
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Country", typeof(string)));
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Number", typeof(int)));
            dt.Columns.Add(new DataColumn("Position", typeof(string)));
 
            List<Player> players = new List<Player>(Club.GetPlayers());
 
            foreach (Player p in players)
            {
                DataRow r = dt.NewRow();
                r["Country"] = p.Country;
                r["Name"] = p.Name;
                r["Number"] = p.Number;
                r["Position"] = p.Position.ToString();
                dt.Rows.Add(r);
            }
 
            this.playersGrid.ItemsSource = dt.DefaultView;
        }

The GridView is not grouped initially when bound to the DataView. When you set the ItemsSource = dt it is grouped.
In my application I use a typed DataTable and the GridView is grouping but the aggregates don't show up the first time. Grouping with Drag'n'Drop always seems to work. When I set the ItemsSource directly to the DataTable everything looks ok until you try to expand a collapsed group. Then the GridView starts throwing RowNotInTable-Exceptions.
Any idea how to get XAML-defined groups and aggrgates working when using a DataTable?

Best Regards
Steffen
0
Steffen
Top achievements
Rank 1
Veteran
answered on 19 Aug 2010, 11:00 AM
Hi,

it seems that Column-Aggregates are not showing up in groups when grouping programmtically using a DataView as ItemsSource in my application.
I can not tell if this also happens in the example because the Group is not showing up if I use a DefaultView as ItemsSource instead of the IEnumerable<>. GroupDescriptors.Count is 1 but there's no Group.

How can I group programmatically to get the same result as grouping per Drag'n'Drop?

Best Regards
Steffen


0
Steffen
Top achievements
Rank 1
Veteran
answered on 19 Aug 2010, 11:28 AM
I found the initial problem in the forum:

http://www.telerik.com/community/forums/silverlight/gridview/group-footer-s-aggregate-values-not-shown.aspx

So programmatically grouping is really different from UI-grouping! I'm going to try the posted solution.

Best Regards
Steffen
0
Accepted
Stefan Dobrev
Telerik team
answered on 19 Aug 2010, 01:01 PM
Hi Steffen,

When you when you want to group and your source collection does not have the CLR metadata about your member type you should explicitly set it in the GroupDescriptor. So using GroupDescriptor.MemberType = typeof(string) or in XAML via x:Type markup extension should do the work.

This extra step is required only in special cases like DataView, DataTable, ICustomTypeDescriptor or XmlNode collections.

Hope this helps,
Stefan Dobrev
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
Steffen
Top achievements
Rank 1
Veteran
answered on 19 Aug 2010, 03:16 PM
Everything works now!
To sum it up:

1.) Even if RadGridView seems to recognize the DataTypes of a DataView (it uses the right CellEditControls) the DataTypes have to be set explicitly for GroupDescriptors to work.

2.) Grouping programmatically is not the same than grouping with drag'n'drop: ColumnAggregates are not showing up when grouping programmatically even they are defined in xaml. To work around this I apply all Grouping, GroupAggregates, ColumnAggregates and Sorting in code behind - triggered by RadGridview's  Loaded-Event. If the GridView is not visible(loaded) programmatic grouping with aggregates will not lead to the desired result. Disableing virtualization doesn't seem to make a difference.


Best Regards
Steffen
 
Tags
GridView
Asked by
Steffen
Top achievements
Rank 1
Veteran
Answers by
Steffen
Top achievements
Rank 1
Veteran
Stefan Dobrev
Telerik team
Share this question
or