我已经创建了一个数据表作为我的datagridview的源,如下所示:
Dim dt As New DataTable
dt.Clear()
DataGridView1.DataSource = dt
dt.Columns.Add("Customer")
dt.Columns.Add("Dtime")
dt.Columns.Add("Title")
dt.Columns.Add("EventID")
EventID是数字,将传递给一个新的表单,告诉它打开哪个记录(该位工作我在另一个表单上使用它。)
我试过了:
event = DataGridView1.SelectedRows(e.RowIndex).Cells(3).Value.ToString
event = Convert.ToInt32(DataGridView1.SelectedRows(0).Cells(3).Value.ToString)
event = Convert.ToInt32(DataGridView1.Item("EventID", DataGridView1.CurrentRow.Index).Value.ToString)
以及我在本网站和其他网站上发现的其他十几种方式,但我一直都会遇到同样的错误:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
这让我疯了,我做错了什么?请帮忙!
答案 0 :(得分:1)
event = DataGridView1.Rows(e.RowIndex).Cells(3).Value.ToString()