简体   繁体   中英

Selected cell in dataGridView1

Hey guys so I'm trying to receive the column/row of the last edited cell however when I use the following code, what I receive is the cell that I select next(by clicking), since it is the one that is being selected.

Any way around this? Maybe I just don't have the right properties for the dataGridView

private void dataGridView1_CellEndEdit_1(object sender, DataGridViewCellEventArgs e)
{
         int column = dataGridView1.SelectedCells[0].ColumnIndex;
         int row = dataGridView1.SelectedCells[0].RowIndex;
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        int column = e.ColumnIndex;
        int row = e.RowIndex;
    }

DataGridViewCellEventArgs provides data for DataGridView events related to cell and row operations. It exposes two properties ColumnIndex and RowIndex

int column = e.ColumnIndex;
int row = e.RowIndex;

More: As @Mr_Green pointed, e.ColumnIndex and e.RowIndex will be -1 for ColumnHeader & RowHeader .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM