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

SfDataGrid SelectedItems - how to clear or set?

Hi all,

I am still experimenting with the SfDataGrid and would like to know how to adjust the SelectedItems in the grid, while the property SelectedItems itself is readonly. Could not find any code samples for it...

Does someone have a magical tip for this?

Kind regards,
Michel.


3 Replies

HN Harikrishnan N Syncfusion Team May 29, 2015 05:50 AM UTC

Hi Michel,

Thank you for contacting Syncfusion support.

We have analyzed your requirement and we have added support for adjusting SelectedItems. This will be included in our upcoming Service pack release which is scheduled to release by the end of this week.


You can achieve your requirement when the SelectionMode is Multiple as in the below code snippet.

SfDataGrid sfGrid;

ViewModel viewModel;

protected override void OnCreate(Bundle bundle)

{

    base.OnCreate(bundle);

    SetContentView(Resource.Layout.Main);

    sfGrid = new SfDataGrid(BaseContext);

    viewModel = new ViewModel();

    sfGrid.ItemsSource = viewModel.OrdersInfo;

    sfGrid.SelectionMode = SelectionMode.Multiple;

    Button selectedItems = new Button(this.BaseContext);

    selectedItems.Text = "Set Selection";

    selectedItems.Click += SetSelection_Click;

    LinearLayout layout = (LinearLayout)FindViewById(Resource.Id.Linear);

    layout.AddView(selectedItems);

    layout.AddView(sfGrid);

}


void SetSelection_Click(object sender, EventArgs e)

{

    //For adding an item in SelectedItems

    sfGrid.SelectedItems.Add(viewModel.OrdersInfo[0]);

    //For removing an item in SelectedItems

    sfGrid.SelectedItems.RemoveAt(0);

    //For clearing the Selection

    sfGrid.SelectedItems.Clear();
}




Please let us know if you require further assistance.

Regards,
Harikrishnan


ST Steve January 27, 2017 03:18 AM UTC

try
mySFGrid.SelectionController.SelectedRows.Clear();


DS Divakar Subramaniam Syncfusion Team January 30, 2017 01:03 PM UTC

Hi Steve, 
  
Thanks for the update. You can achieve your requirement using the mentioned code (SelectedRows.Clear()) also. Please let us know if you need any other assistance from us. 
  
Regards, 
Divakar. 


Loader.
Live Chat Icon For mobile
Up arrow icon