Editing Issue when grouping is enabled on datagrid

Mar 6, 2009 at 5:12 AM
When we have grouping enabled in datagrid. If user edit any entry the entry automatically moves to the last row in the group.
The issue is also present in  DataGridCTP Sample.

Please suggest.
Mar 11, 2009 at 1:51 PM
I am unable to repro your issue.  Do you mind posting some code and some context around the issue.
Apr 8, 2009 at 1:14 PM
Sorry for late reply.

We tried the new DataGrid v1 (WPFToolkit v3.5.40128.1) released in March'09, but are still facing with same issue. 
Here is xaml and code behind which we wrote for testing.

-- Window1.xaml --
<Window x:Class="WpfToolKitTestBed.Window1"
        xmlns:toolkit= "clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    Title="Window1" WindowState="Maximized" >
    <Grid  Margin="10" Name="myGrid">
        <toolkit:DataGrid Name="channelGrid" 
                             AutoGenerateColumns="False" CanUserAddRows="False" IsSynchronizedWithCurrentItem="True" 
                             CanUserDeleteRows="False" SelectionMode="Single" 
                            <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Padding="3"/>

                <toolkit:DataGridTextColumn Width="Auto" 
                                       Binding="{Binding Path=Id}" />
                <toolkit:DataGridTextColumn Width="120"                                        
                                       Binding="{Binding Path=Name}"  />
                <toolkit:DataGridCheckBoxColumn Width="150" Header="Likes Cake" 
                                                Binding="{Binding Path=LikesCakes}" />
                <toolkit:DataGridTextColumn Width="*" Header="Cake Type" 
                                       Binding="{Binding Path=CakeType}" />


-- Window1.xaml  Ends here--

-- Window1.xaml.cs --

using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;

namespace WpfToolKitTestBed {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window {

        public Window1() {

            List<Person> personData = new List<Person>();

            // generate data...
            personData.Add(new Person { Id = 1, Name = "John", LikesCakes = true, CakeType = "Vanilla" });
            personData.Add(new Person { Id = 2, Name = "Mike", LikesCakes = false, CakeType = "Chocolate" });
            personData.Add(new Person { Id = 3, Name = "Stuart", LikesCakes = false, CakeType = "Vanilla" });
            personData.Add(new Person { Id = 4, Name = "John", LikesCakes = true, CakeType = "Strawberry" });
            personData.Add(new Person { Id = 5, Name = "Jill", LikesCakes = true, CakeType = "Plum" });
            personData.Add(new Person { Id = 6, Name = "Mike", LikesCakes = true, CakeType = "Vanilla" });
            personData.Add(new Person { Id = 7, Name = "John", LikesCakes = false, CakeType = "Milk" });

            channelGrid.ItemsSource = personData;
            this.Loaded += new RoutedEventHandler(Window1_Loaded);

        void Window1_Loaded(object sender, RoutedEventArgs e) {            
            ICollectionView view1 = CollectionViewSource.GetDefaultView(channelGrid.ItemsSource);
            view1.GroupDescriptions.Add(new PropertyGroupDescription("Name"));

    public class Person {

        public string Name { get; set; }
        public int Id { get; set; }
        public bool LikesCakes { get; set; }
        public string CakeType { get; set; }


-- Window1.xaml.cs ends here --

The data grid created, is grouped by Name property in Person class. If we try to edit any of the column values (other than Name), the edited row is placed at the bottom within same group.

Hope you can reproduce with the code provided.

Thanks in Advanced,

Apr 14, 2009 at 2:41 PM
This is by design.  Note that it only moves the entry if you edit a cell from the Name column.  The reason is b/c that is what is grouped.  If you create a new name it will create a group.  Since you don't have any sorting descriptions it will add this to the bottom of the list.  If you edit any of the other cells the entry will not move to the bottom.
Apr 15, 2009 at 7:16 AM
I am afriad that the row entry is moved to bottom of the group even when editing is done in any other cells (e.g. CakeType column ). Am I missing something in the code mentioned above? 
Jun 8, 2009 at 6:29 PM


I have the same problem with March 2009 wpf datagrid editing and grouping.

Is anybody who know how to solve this issue?

Thank you.

Jun 9, 2009 at 11:53 AM

2 vinsibal:

Yes I confirm that moving to the bottom occured when changing any editable cell in the grid, surely not only grouping-field.


Jun 22, 2009 at 3:29 PM

Vinsibal, I too confirm that editing a cell, no matter which one, moves the row to the bottom of the grouping. When do you expect this to be addressed?

Jun 23, 2009 at 5:05 AM

This is a bug in the CollectionView code related to grouping.  It is fixed in dev10.  As a workaround you can set a sortdescription on one of the columns that's not being grouped.

Jun 23, 2009 at 3:23 PM

I'm applying sort descriptions on three columns, none with grouping.

                Source="{Binding Path=.}">
                    <scm:SortDescription PropertyName="Comportment"/>
                    <scm:SortDescription PropertyName="IRPriority"/>
                    <scm:SortDescription PropertyName="IRCode"/>
                    <PropertyGroupDescription PropertyName="License"/>

I notice that as long as all rows and columns are visible within the datagrid window (no scrollbars) editing doesn't move the row to the bottom of the grouping, but if there are any rows or columns outside of the window, then editing does move the row. I tried setting both row and column virtualization to false and that did not work either. Is there another workaround besides what you proposed?