该语法DataGridViewPayments.Item("Amount", DataGridViewPayments.CurrentRow.Index)
将在名为“Amount”的列(假设它存在)与当前行索引(假设 CurrentRow 不是 Nothing)的交叉处获取DataGridViewCell 。
要获取该单元格的值,您需要引用名为 DataGridViewCell 的属性Value
DataGridViewPayments.Item("Amount", DataGridViewPayments.CurrentRow.Index).Value
该Amount
列表明存在一个数值,但请记住,如果当前单元格为空或 null,您可能会遇到异常。在这种情况下,最好这样做:
object o = DataGridViewPayments.Item("Amount", DataGridViewPayments.CurrentRow.Index).Value
if o Is Nothing OrElse o.ToString = "" then
MsgBox("The cell is empty or null", "Message Title")
else
MsgBox("The cell value is " + o.ToString, "Message Title")
end if