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

SelectRow and SelectCell in sfDataGrid

Hi.


I wanna select row index 2 

So I did like this

sfDataGrid1.SelectRows(2,2); (and  sfDataGrid1.SelectRows(1,1) either)

this is not working, but

sfDataGrid1.SelectedIndex = 1;

this is working.

If selecting row is needed, can I use SelectedIndex only?

How can I select row(s) with SelectRow(,) ?

Thank you.



1 Reply

VS Vijayarasan Sivanandham Syncfusion Team January 31, 2023 11:48 AM UTC

Hi Sangyong Lee,

Find the response to the queries,

Query

Response

If selecting row is needed, can I use SelectedIndex only?

 


You can select a single row by using the SelectedIndex in SfDataGrid. However, SfDataGrid allows you to select one or more rows or cells through UI interaction via mouse and programmatic selection. For more information related to selection, please refer to the user guide documentation link below.

UG Link: https://help.syncfusion.com/windowsforms/datagrid/selection

https://help.syncfusion.com/windowsforms/datagrid/selection#programmatic-selection

How can I select row(s) with SelectRows(,) ?


SfDataGrid allows the selection of a range of rows through the SelectRows method. This is applicable only for Multiple and Extended selection modes.

API Link:
SelectRows

To select multiple rows in SfDataGrid using the SelectRows method, set the SelectionMode property to either Extended or Multiple. See the code example below:

//Multiple row selection

sfDataGrid1.SelectionMode = GridSelectionMode.Extended;


private void btnSelectRows_Click(object sender, System.EventArgs e)

{

     //Select the single row in SfDataGrid

     //sfDataGrid1.SelectRows(2, 2);

 

     //Select the row between 2 to 5 in SfDataGrid

     sfDataGrid1.SelectRows(2, 5);

}


UG Link:
https://help.syncfusion.com/windowsforms/datagrid/selection#multiple-row-or-cell-selection

https://help.syncfusion.com/windowsforms/datagrid/selection#process-selection-using-methods


Find the sample in the attachment.

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_3940d6cf.zip

Loader.
Live Chat Icon For mobile
Up arrow icon