vb.net,如何获取datagridview最后一个单元格的行和列索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23183607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:25:39  来源:igfitidea点击:

vb.net, How to get datagridview last cell row and column index

vb.netdatagridview

提问by Adhir ch Mondal

I have create a datagridview in vb.net with several fields, and Input data from keyboard to fill-up the fields,

我在 vb.net 中创建了一个包含多个字段的 datagridview,并从键盘输入数据以填充字段,

Now I Want to know How the last cell index (row and column) for storing data from a particular location of this datagridview. Please tell me what to do for store last location cell index (Row and Column) of datagridview.

现在我想知道最后一个单元格索引(行和列)如何存储来自这个 datagridview 的特定位置的数据。请告诉我如何存储 datagridview 的最后位置单元格索引(行和列)。

回答by Deja Vu

Here you can get the last cell's value:

在这里您可以获得最后一个单元格的值:

        Dim CellValue As String
        With DataGridView1
          CellValue = .Rows(.RowCount - 1).Cells(.ColumnCount - 1).Value
        End With

If the last row is empty then use:

如果最后一行为空,则使用:

        Dim CellValue As String
        With DataGridView1
          CellValue = .Rows(.RowCount - 2).Cells(.ColumnCount - 2).Value
        End With