After the grouping sfDataGrid1. SelectedIndex have error

sfDataGrid1.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "店号" }); sfDataGrid1.ExpandAllGroup(); int i = sfDataGrid1.SelectedIndex; var records = sfDataGrid1.View.Records; var dataRowView = records[i].Data as DataRowView;


After grouping I want to take the data of the currently selected row,
so there is an error, and the data fetched is wrong.



4 Replies 1 reply marked as answer

SB Sweatha Bharathi Syncfusion Team June 12, 2023 01:30 PM UTC


chinamayu ,

We are currently checking your reported problem with provided information and we need a time to validate this. We will update you with further details on , June 14 2023.



SB Sweatha Bharathi Syncfusion Team June 14, 2023 01:04 PM UTC


chinamayu ,


In case of grouping, we are unable to use SelectedIndex directly because records do not consider grouping elements as index values and we have prepared a sample based on your requirements. Please review the sample and let us know if you require any further assistance.


Attachment: Sample_57337f2a.zip


YM yu ma replied to Sweatha Bharathi June 15, 2023 05:41 AM UTC

Sweatha Bharathi

var recordIndex = sfDataGrid1.TableControl.ResolveToRecordIndex(sfDataGrid1.TableControl.ResolveToRowIndex(sfDataGrid1.SelectedItem));
if (recordIndex < 0)
    return;
if (sfDataGrid1.View.TopLevelGroup != null)
{
    var record = sfDataGrid1.View.TopLevelGroup.DisplayElements[recordIndex];

   //What is this data taken out, record["id"] used like this error

    //   System.Data.DataRow row = ((dynamic)sfDataGrid1.SelectedItem).Row;
    // row["id"]  
    // This code program can run, but do not know if there is an exception

 
}
else
{
    var record1 = sfDataGrid1.View.Records[sfDataGrid1.SelectedIndex].Data as DataRowView;
}



Marked as answer

SB Sweatha Bharathi Syncfusion Team June 16, 2023 10:24 AM UTC

Hi chinamayu , 


You can also use this way to retrieve the data row by using the selected item value.



Loader.
Up arrow icon