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

Possible column index bug with ShowRowHeader

Hi,

If ShowRowHeader="False", I can lookup the index of a column using SfDataGrid.Columns.IndexOf() and then use that index in a call to SfDataGrid.MoveCurrentCell() to make a cell in that column current. However, if ShowRowHeader="True", the same call to MoveCurrentCell() would make the cell to the left of the intended cell current. This may be problematic because you have to check the current state of ShowRowHeader in order to offset the column index properly when setting a cell current.

Or should a different API be used to achieve selecting a current cell based on a column index independent of ShowRowHeader?

Regards,

Sam

3 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team May 10, 2017 03:56 AM UTC

Hi Sam, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your query.  You can achieve your requirement by two way as shown below. 
 
Way 1: You can resolve and get the appropriate column index by considering the ShowRowHeader  column as shown in the below code, 
 
Code Snippet: 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    var colIndex = this.dataGrid.Columns.IndexOf(this.dataGrid.Columns["QS1"])+(this.dataGrid.ShowRowHeader?1:0); 
    this.dataGrid.MoveCurrentCell(new RowColumnIndex(1, colIndex), true); 
} 
 
Way 2: Also, you can use ResolveToScrollColumnIndex method to get the column index as shown below, 
 
Code Snippet: 
private void Button_Click1(object sender, RoutedEventArgs e) 
{ 
    var colIndex = this.dataGrid.Columns.IndexOf(this.dataGrid.Columns["QS1"]); 
    var index1 = this.dataGrid.ResolveToScrollColumnIndex(colIndex); 
    this.dataGrid.MoveCurrentCell(new RowColumnIndex(1, index1), true); 
} 
 
 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 
 



SC Sam Chan May 11, 2017 10:55 AM UTC

Hi Muthukumar,

Thank you for the reply. Both solutions work fine.

Regards,

Sam


MK Muthukumar Kalyanasundaram Syncfusion Team May 12, 2017 04:47 AM UTC

Hi Sam, 
 
Thanks for the update. Please let us know if you need any other assistance. 
 
Regards, 
Muthukumar K 


Loader.
Live Chat Icon For mobile
Up arrow icon