Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get row's and cell's index of a just edited cell in DataGrid

Tags:

c#

wpf

datagrid

I'm having problem with finding row's and cell's index of a just edited cell in DataGrid. I'm using CellEditEnding event to know when the cell has been edited.

Till now I've managed to do something like this. Col1 contains property DisplayIndex and that is index of selected column but I can't find in the same way.

    private void DataGridData_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        DataGridColumn col1 = e.Column;
        DataGridRow row1 = e.Row;
    }
like image 277
Patryk Avatar asked Mar 24 '23 00:03

Patryk


1 Answers

I've got it working now. This is how it looks like:

private void DataGridData_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        DataGridColumn col1 = e.Column;
        DataGridRow row1 = e.Row;
        int row_index = ((DataGrid)sender).ItemContainerGenerator.IndexFromContainer(row1);
        int col_index = col1.DisplayIndex;
    }
like image 140
Patryk Avatar answered Apr 03 '23 06:04

Patryk