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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





123403 Mar 15,2016 09:21 AM UTC Mar 17,2016 04:27 AM UTC WPF 6
Tags: SfDataGrid
Asked On March 15, 2016 09:21 AM UTC

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.


Replied On 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

Replied On 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.

Jayapradha S [Syncfusion]
Replied On 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


Replied On March 17, 2016 12:57 AM UTC

Oh thanks! I feel so silly :)

Jayapradha S [Syncfusion]
Replied On March 17, 2016 04:24 AM UTC

Hi Will,

Thank you for your update.

Please let us know if you require any other assistance.


Jayapradha S [Syncfusion]
Replied On March 17, 2016 04:27 AM UTC

Hi CHLoh,

Thank you for your update. 

Please let us know if you require any other assistance.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon