大家好,所以下面的代码会在点击特定单元格时打开领导者的详细视图。我试图这样做,当单击一个单元格时,它会将具有所选单元格的LeaderID的任何事件的行位置添加到数组" le"。
然而这行代码
If dgdEvents.Rows(n).Cells("LeaderID").Value = .Rows(i).Cells("LeaderID").Value Then
导致以下错误
未处理的类型' System.ArgumentOutOfRangeException'发生在mscorlib.dll
其他信息:索引超出范围。必须是非负数且小于集合的大小。
Public Sub dgdLeaders_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgdLeaders.CellClick
dbv.EditLeader()
Dim i As Integer
Dim n As Integer
Dim c As Integer = 0
With dgdLeaders
If e.RowIndex >= 0 Then
i = .CurrentRow.Index
While n <> dgdEvents.Rows.Count + 1
If dgdEvents.Rows(n).Cells("LeaderID").Value = .Rows(i).Cells("LeaderID").Value Then
le(c) = n
c = c + 1
End If
n = n + 1
End While
tbid.Text = .Rows(i).Cells("LeaderID").Value.ToString
tbfn.Text = .Rows(i).Cells("Forename").Value.ToString
tbsn.Text = .Rows(i).Cells("Surname").Value.ToString
dtpdob.Value = .Rows(i).Cells("DOB").Value
tbsr.Text = .Rows(i).Cells("Role").Value.ToString
tbpc.Text = .Rows(i).Cells("Postcode").Value.ToString
tbht.Text = .Rows(i).Cells("HomeTel").Value.ToString
tbmt.Text = .Rows(i).Cells("MobileTel").Value.ToString
tbal1.Text = .Rows(i).Cells("AddressLine1").Value.ToString
tbal2.Text = .Rows(i).Cells("AddressLine2").Value.ToString
tbc.Text = .Rows(i).Cells("City").Value.ToString
tbea.Text = .Rows(i).Cells("EmailAddress").Value.ToString
l = i
n = 0
End If
End With
End Sub