Never bind to DataTable.DefaultView?

6 posts, 1 answers
  1. Steffen
    Steffen avatar
    77 posts
    Member since:
    Mar 2009

    Posted 18 Aug 2010 Link to this post

    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   
  2. Steffen
    Steffen avatar
    77 posts
    Member since:
    Mar 2009

    Posted 19 Aug 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Steffen
    Steffen avatar
    77 posts
    Member since:
    Mar 2009

    Posted 19 Aug 2010 Link to this post

    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


  5. Steffen
    Steffen avatar
    77 posts
    Member since:
    Mar 2009

    Posted 19 Aug 2010 Link to this post

    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
  6. Answer
    Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 19 Aug 2010 Link to this post

    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
  7. Steffen
    Steffen avatar
    77 posts
    Member since:
    Mar 2009

    Posted 19 Aug 2010 Link to this post

    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
     
Back to Top
UI for WPF is Visual Studio 2017 Ready