We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Programmatically set binded SelectedItem does not change SfDataGrid.SelectedItems and UI

Hi, my SfDataGrid.SelectedItem is binded (TwoWay) to a property in ViewModel.
After changing ViewModel.SelectedItem, SfDataGrid does not select the selected item on-screen. SfDataGrid.SelectedItems is not updated too.
Is this a bug?

In View:
<Syncfusion:SfDataGrid x:Name="sfdatagrid"
                               ItemsSource="{Binding EmployeeDetails}"
                               SelectedItem="{Binding SelectedItem, Mode=TwoWay}"

In ViewModel:
        private object selecteditem;
        public object SelectedItem {
            get  { return selecteditem; }
            set {
                selecteditem = value;
        NewRow() {
            employeelist.Add(new Model());
            selecteditem = employeelist[employeelist.Count-1];
            // new item is not selected in UI, and SfDataGrid.SelectedItems does not have this item in it too.


6 Replies

BR bruce March 16, 2016 01:19 AM UTC

I've attached a sample which was modified from a sample downloaded from a thread in this forum.
I added a "New Row" button which demonstrates the issue.
Thanks !

Attachment: WPF_508e1d95.rar

BR bruce March 16, 2016 01:24 AM UTC

My intention is to allow the ViewModel to control the SelectedItem, without depending on View, for the sake of MVVM separation and Unit Test.
For example, in ViewModel.NewRow() command, it will add a new row to a collection and set the SelectedItem to the new row. The row in the grid should be selected and SelectedItems should include this item too.

JS Jayapradha S Syncfusion Team March 16, 2016 10:18 AM UTC

Hi  CHLoh,

Thank you for contacting Syncfusion Support.

We have analyzed your query with your updated sample. You didn’t implement the interface INotifyPropertyChanged in ViewModel class and so new row will not be selected. We have modified the sample and this new selected item has been added in SfDataGrid.SelectedItems.

Please find the modified sample from the following location,
Sample : http://www.syncfusion.com/downloads/support/forum/123403/ze/WPF-952906245


BR bruce March 17, 2016 12:57 AM UTC

Oh thanks! I feel so silly :)

JS Jayapradha S Syncfusion Team March 17, 2016 04:24 AM UTC

Hi Will,

Thank you for your update.

Please let us know if you require any other assistance.


JS Jayapradha S Syncfusion Team March 17, 2016 04:27 AM UTC

Hi CHLoh,

Thank you for your update. 

Please let us know if you require any other assistance.


Live Chat Icon For mobile
Up arrow icon