I have a form with sub grids, and I was trying to apply a context menu to them. The context menu works fine when used from the parent grid, but when used from the children grids there is no way to retrieve the current item or row that I can see. I have attached an example. In the first two events that are bolded, the indexes always return as -1.
private void transformsGrid_DeleteRowClicked(object sender, EventArgs e)
{
Debug.WriteLine(nameof(transformsGrid_DeleteRowClicked));
Debug.WriteLine($"SelectedIndex: {_transformsGrid.SelectedIndex}, CurrentCell.RowIndex: {_transformsGrid.CurrentCell.RowIndex}");
}
private void columnsGrid_DeleteRowClicked(object sender, EventArgs e)
{
Debug.WriteLine(nameof(columnsGrid_DeleteRowClicked));
Debug.WriteLine($"SelectedIndex: {_columnsGrid.SelectedIndex}, CurrentCell.RowIndex: {_columnsGrid.CurrentCell.RowIndex}");
}
private void tablesGrid_DeleteRowClicked(object sender, EventArgs e)
{
Debug.WriteLine(nameof(tablesGrid_DeleteRowClicked));
Debug.WriteLine($"SelectedIndex: {tablesGrid.SelectedIndex}, CurrentCell.RowIndex: {tablesGrid.CurrentCell.RowIndex}");
}
HI Tim,
You can retrieve the selected index of the detailsview daatgrid using below
code snippet,
C#:
|
private void transformsGrid_DeleteRowClicked(object sender, EventArgs e) { Debug.WriteLine(nameof(transformsGrid_DeleteRowClicked)); Debug.WriteLine($"SelectedIndex: {(tablesGrid.SelectedDetailsViewGrid as SfDataGrid).SelectedIndex}, CurrentCell.RowIndex: {(tablesGrid.SelectedDetailsViewGrid as SfDataGrid).CurrentCell.RowIndex}"); }
private void columnsGrid_DeleteRowClicked(object sender, EventArgs e) { Debug.WriteLine(nameof(columnsGrid_DeleteRowClicked)); Debug.WriteLine($"SelectedIndex: {(tablesGrid.SelectedDetailsViewGrid as SfDataGrid).SelectedIndex}, CurrentCell.RowIndex: {(tablesGrid.SelectedDetailsViewGrid as SfDataGrid).CurrentCell.RowIndex}"); }
private void tablesGrid_DeleteRowClicked(object sender, EventArgs e) { Debug.WriteLine(nameof(tablesGrid_DeleteRowClicked)); Debug.WriteLine($"SelectedIndex: {tablesGrid.SelectedIndex}, CurrentCell.RowIndex: {tablesGrid.CurrentCell.RowIndex}"); } |
We have prepared the sample for the same. Please have a look on
this and revert us if you need further assistance for this.
Regards,
Dhanasekar M.
So, I FINALLY got back around to looking at this, and your solution is giving the wrong information. It applies to the parent grid, and NEVER EVER changes no matter what row / cell right click in a sub grid.
Ahhhh I see now... you need to go down as many levels as there are subgrids. So for the example, to get to the transform grid you need to do like so:
((tablesGrid.SelectedDetailsViewGrid as SfDataGrid).SelectedDetailsViewGrid as SfDataGrid).CurrentCell
Here is a modified version of the example code that gets the correct output:
private void transformsGrid_DeleteRowClicked(object sender, EventArgs e)
{
Debug.WriteLine(nameof(transformsGrid_DeleteRowClicked));
var grid = ((tablesGrid.SelectedDetailsViewGrid as SfDataGrid).SelectedDetailsViewGrid as SfDataGrid);
Debug.WriteLine($"SelectedIndex: {grid.SelectedIndex}, CurrentCell.ColumnIndex: {grid.CurrentCell.ColumnIndex}, CurrentCell.RowIndex: {grid.CurrentCell.RowIndex}");
}
private void columnsGrid_DeleteRowClicked(object sender, EventArgs e)
{
Debug.WriteLine(nameof(columnsGrid_DeleteRowClicked));
var grid = (tablesGrid.SelectedDetailsViewGrid as SfDataGrid);
Debug.WriteLine($"SelectedIndex: {grid.SelectedIndex}, CurrentCell.ColumnIndex: {grid.CurrentCell.ColumnIndex}, CurrentCell.RowIndex: {grid.CurrentCell.RowIndex}");
}
private void tablesGrid_DeleteRowClicked(object sender, EventArgs e)
{
Debug.WriteLine(nameof(tablesGrid_DeleteRowClicked));
Debug.WriteLine($"SelectedIndex: {tablesGrid.SelectedIndex}, CurrentCell.RowIndex: {tablesGrid.CurrentCell.RowIndex}");
}
Hi Tim,
We are glad that the reported issue was resolved on your side. Please let us know if you need any other details on this. As always, we will be happy to assist you.
Regards,
Dhanasekar M.