Home Forums WPF controls Xceed DataGrid for WPF Order of fields/property change notification/repainting

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25301 |

    I was working with the Xceed DataGrid and binding to an observable
    collection of objects. The object class type implements
    INotifyPropertyChanged, and has 3 properties, a, b, and c. Fields a and
    b are integers, and c is a calculated field that is the sum of a and b.

    I used the following code to bind to the grid:

    <Window x:Class=”TestPropertyNotify.Window1″
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    xmlns:local=”clr-namespace:TestPropertyNotify”
    xmlns:xc=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    Title=”Test Property Notification” Height=”281″ Width=”800″>
    <Grid>
    <xc:DataGridControl ItemsSource=”{Binding Source={x:Static local:abc.Test}}” AutoCreateColumns=”False”>
    <xc:DataGridControl.Columns>
    <xc:Column Title=”c ( = a + b)” FieldName=”c” ReadOnly=”True” />
    <xc:Column Title=”a” FieldName=”a” />
    <xc:Column Title=”a” FieldName=”a” />
    <xc:Column Title=”b” FieldName=”b” />
    <xc:Column Title=”c ( = a + b)” FieldName=”c” ReadOnly=”True” />
    </xc:DataGridControl.Columns>
    </xc:DataGridControl>
    </Grid>
    </Window>

    And this is the .cs file:

    namespace TestPropertyNotify
    {
    public partial class Window1 : Window
    {
    public Window1()
    {
    abc.Test.Add(new abc() { a = 1, b = 2 });
    abc.Test.Add(new abc() { a = 3, b = 5 });
    InitializeComponent();
    }
    }

    public class abc : INotifyPropertyChanged
    {
    public static ObservableCollection<abc> Test = new ObservableCollection<abc>();

    private int _a;
    public int a
    {
    get { return _a; }
    set { _a = value; OnPropertyChanged(“a”); OnPropertyChanged(“c”); }
    }

    private int _b;
    public int b
    {
    get { return _b; }
    set { _b = value; OnPropertyChanged(“b”); OnPropertyChanged(“c”); }
    }

    public int c
    {
    get { return _a + _b; }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
    if (null != PropertyChanged)
    {
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    }
    }
    }

    The problem is that when I modify the 2nd a (the 3rd column), the first
    c and first a do not get updated until the next time I modify the row.
    The property change notification occurs, but the row does not get
    repainted until the next time a change is made to any cell on that row.
    However, the 4th and 5th columns do get updated correctly.

    Is there anything in my sample application that I am doing incorrectly,
    or do you know if this is an issue with the DataGrid component?

    Imported from legacy forums. Posted by Brian (had 1941 views)

    User (Old forums)
    Member
    Post count: 23064

    I have this problem as well. This problem lies on the fact that Xceed Datagrid update the data on a row basis. So when you go into edit mode, DataGrid will keep a copy of the whole row and push it back to the object when you move out of the row. If you update the underly object on that row when it’s in edit mode, it will have no effect. One workaround you can do is to delay OnPropertyChanged event by using BeginInvoke. I hope Xceed will consider to make another option to let DataGrid to update cell by cell basis.

    Imported from legacy forums. Posted by nat (had 3326 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.