开发者

DataGridView & 'System.NullReferenceException' error

I am trying to load my textboxes with my DataGridView values as follow but I am getting a " A first chance exception of type 'System.NullReferenceException' occurred in Microsoft.VisualBasic.dll开发者_StackOverflow" error, the program is still workable though despite this. Anyone knows what's wrong?

Many Thanks.

Code:

For iloop = 0 To DataGridView2.Rows.Count
        For Each cCtrl As Control In Panel2.Controls
            If TypeOf cCtrl Is TextBox Then
                Dim txtBox As TextBox
                txtBox = cCtrl
                If (txtBox.Name.Substring(9, 6)) = ((DataGridView2.Rows.Item(iloop).Cells(0).Value).substring(0, 6)) Then
                    txtBox.Text = DataGridView2.Rows.Item(iloop).Cells(3).Value
                End If
            End If
        Next
    Next


Add an if condition for If DataGridView2.Rows.Item(iloop).Cells(0).Value IsNot Nothing Then before you take the substring of the value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜