简体   繁体   English

dataGridView1中的选定单元格

[英]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 也许我只是没有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. DataGridViewCellEventArgs为与单元格和行操作相关的DataGridView事件提供数据。 It exposes two properties ColumnIndex and RowIndex 它公开了两个属性ColumnIndexRowIndex

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

More: As @Mr_Green pointed, e.ColumnIndex and e.RowIndex will be -1 for ColumnHeader & RowHeader . 更多:作为@Mr_Green指出, e.ColumnIndexe.RowIndex将是-1ColumnHeader & RowHeader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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