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.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid.SelectedItems: select multiple items by code

Thread ID:

Created:

Updated:

Platform:

Replies:

119221 May 25,2015 03:40 AM May 26,2015 10:18 PM WinRT 3
loading
Tags: SfDataGrid
Benito Gomez
Asked On May 25, 2015 03:40 AM

Hi!

I'm using a SfDataGrid control with this configuration

dataGrid.SelectionMode = GridSelectionMode.Multiple;
dataGrid.SelectionUnit = GridSelectionUnit.Row;

I'm trying to select some rows of the grid when the user push a button (the grid is on screen). I do this:


dataGrid.SelectedItems.Add( myItemSourceItem );
dataGrid.SelectedItems.Add( myItemSourceItem2 );

Where myItemSourceItem and myItemSourceItem2, are contained in ItemsSource.

The problem is that de rows than not seems to be selected visualy.


However the dataGrid.SelectAll() methods works properly and select all rows as aspected. Am I forgetting something?

Thanks in advance!


Jayapradha S [Syncfusion]
Replied On May 26, 2015 07:44 AM

Hi Benito,

Thank you for using Syncfusion products.

We analyzed your reported issue and defined the same SfDataGrid control configuration which you have shared. You can add the items into selecteditems list and you can reflect that selection in visual also. We are unable to replicate the issue “Selection is not reflected in view when adding the items in SelectedItem list” as you reported and please share the Essential studio product version which you are using currently.


Please find the code snippet as follows :

Code Snippet:

private void Button_Click(object sender, RoutedEventArgs e)

{

var viewModel = sfDataGrid.DataContext as ViewModel;

var selectedItem = viewModel.OrderDetails[1];

var secondItem = viewModel.OrderDetails[4];

this.sfDataGrid.SelectedItems.Add(selectedItem);

this.sfDataGrid.SelectedItems.Add(secondItem);
}

<syncfusion:SfDataGrid x:Name="sfDataGrid"

SelectionUnit="Row"

AutoGenerateColumns="False"

SelectionMode="Multiple"
ItemsSource="{Binding OrderDetails}">



We have prepared a sample for your requirement and you can download the sample from the following location:

Sample Link: SfDataGrid.zip

Please check the attached sample and kindly let us know if you require any further assistance.

Regards,
Jayapradha


Benito Gomez
Replied On May 26, 2015 09:21 AM

Sorry, I just try this morning the issue and works properly. We were using an old version of Essential Studio and all works fine now.

Thank you very much for your attention, your support is always appreciated.

Jayapradha S [Syncfusion]
Replied On May 26, 2015 10:18 PM

Hi Benito,

Thank you for your compliments.

Please let us know if you have any other queries.

Regards,
Jayapradha

CONFIRMATION

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.

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.

;