if (dataGridView1.SelectedRows.Count != 0)
{
DataGridViewRow row = this.dataGridView1.SelectedRows[0];
row.Cells["ColumnName"].Value
}
Thank you
|
void sfDataGrid_SelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e)
{
var selectedItem = this.sfDataGrid.CurrentItem as DataRowView;
var dataRow = (selectedItem as DataRowView).Row;
var cellValue = dataRow["ID"].ToString();
} |
|
var selectedItem = sfDataGrid.SelectedItems[0];
var dataRow = (selectedItem as DataRowView).Row;
var cellValue = dataRow["ID"].ToString(); |
get an error when grouping
{
Object reference not set to an instance of an object
}
can you Reso
Hi Jun Rikson ,
We have analysed your query, it seems that the issue you are encountering occurs during the SelectionChanged event, especially when performing grouping. This is likely due to the creation of records based on the grouping, causing the CurrentItem to not be maintained.
To address this issue, we recommend to set a null check based on the CurrentItem in the SelectionChanged event to handle such scenarios.
Additionally, in our previous update, we provided an option for obtaining selected items in a button click event.
We have also included a sample for your reference. Please review the provided sample and let us know if you have any further concerns on this.
Code Snippet:
|
void sfDataGrid_SelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e) {
if(this.sfDataGrid.CurrentItem != null) { var selectedItem = this.sfDataGrid.CurrentItem as DataRowView; var dataRow = (selectedItem as DataRowView).Row; var cellValue = dataRow["ID"].ToString(); }
} |