Binding SelectedRows

Hi,

I have a SfDataGrid with ItemSources binding to an ObservableCollection<ItemViewModelType>.

I also have a SfListView with  ItemSources  binding  to the same ObservableCollection<ItemViewModelType>.  and SelectedItems also binding  to an ObservableCollection<ItemViewModelType>.

However, I can just binding SfDataGrid's SelectedRows to an ObservableCollection<object> while the object has type is  ItemViewModelType.

So, how can I binding  SfDataGrid's SelectedRows  to the same collection as SfListView's SelectedItems   ?

or how can I update  the SelectedRows whenever the  SfListView's SelectedItems changed and vise vice versa?


Thanks and best regards,
TH


3 Replies 1 reply marked as answer

AP Abinesh Palanisamy Syncfusion Team May 22, 2024 07:55 AM UTC

Hi thanhhai,


Based on the provided details, You can synchronize the SelectedRows of SfDataGrid with the SelectedItems of SfListView and vice versa using data binding. To achieve this, you can bind SfListView.SelectedItems directly to SfDataGrid.SelectedRows. This binding ensures that whenever you select rows in the SfDataGrid, they are added to SfListView.SelectedItems, and similarly, when you select items in the SfListView, they are added to SfDataGrid.SelectedRows.  We have attached a sample for your reference. Please consult the following sample for further information. If you have any further concerns, please feel free to reach out.


Regards,

Abinesh P


Attachment: SfDataGrid_d915f250.zip

Marked as answer

TH Thanh Hai Dang June 3, 2024 03:58 PM UTC

Thank you,  Abinesh Palanisamy.

I confirm that I resolved this issue.




NY Nirmalkumar Yuvaraj Syncfusion Team June 4, 2024 08:58 AM UTC

Hi Thanh,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help.


Regards,

Nirmalkumar


Loader.
Up arrow icon