Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    frmDisplayLockerInfo.Show()
    frmDisplayLockerInfo.TextBox2.ReadOnly = False
    frmDisplayLockerInfo.TextBox3.ReadOnly = False
    frmDisplayLockerInfo.TextBox4.ReadOnly = False
    frmDisplayLockerInfo.TextBox5.ReadOnly = False
    frmDisplayLockerInfo.TextBox6.ReadOnly = False
    frmDisplayLockerInfo.TextBox7.ReadOnly = False
    frmDisplayLockerInfo.TextBox8.ReadOnly = False
    frmDisplayLockerInfo.TextBox9.ReadOnly = False
    frmDisplayLockerInfo.TextBox10.ReadOnly = False
    frmDisplayLockerInfo.TextBox11.ReadOnly = False
    frmDisplayLockerInfo.TextBox12.ReadOnly = False
    frmDisplayLockerInfo.TextBox13.ReadOnly = False
    frmDisplayLockerInfo.TextBox15.ReadOnly = False
    frmDisplayLockerInfo.TextBox14.ReadOnly = False
    Dim i As Integer
    Dim ds As New DataSet
    i = DataGridView1.CurrentRow.Index
    Label1.Text = i
    frmDisplayLockerInfo.TextBox1.Text = DataGridView1.Item(0, i).Value
    frmDisplayLockerInfo.TextBox13.Text = DataGridView1.Item(1, i).Value
    frmDisplayLockerInfo.TextBox15.Text = DataGridView1.Item(2, i).Value
    frmDisplayLockerInfo.TextBox12.Text = DataGridView1.Item(3, i).Value

    frmDisplayLockerInfo.TextBox2.Text = DataGridView1.Item(4, i).Value
    frmDisplayLockerInfo.TextBox3.Text = DataGridView1.Item(5, i).Value
    'Dim DS As New DataSet
    'If DS.Tables("Locker").Rows(0).Item(6) Is DBNull.Value Then
    'frmDisplayLockerInfo.TextBox4.Text = If(IsDBNull(6), String.Empty, CType(6, String))
    'Else
    'frmDisplayLockerInfo.TextBox4.Text = SafeValue()
    'frmDisplayLockerInfo.TextBox4.Text = DataGridView1.Item(6, i).Value
    'End If
    **If ds.Tables("Locker").Rows(0).Item(6).Equals(System.DBNull.Value) Then
        frmDisplayLockerInfo.TextBox4.Text = DataGridView1.Item(6, i).Value
        'Else
        '    frmDisplayLockerInfo.TextBox4.Text = DataGridView1.Item(6, i).Value
    End If**
    frmDisplayLockerInfo.TextBox5.Text = DataGridView1.Item(7, i).Value
    frmDisplayLockerInfo.TextBox6.Text = DataGridView1.Item(8, i).Value
    frmDisplayLockerInfo.TextBox7.Text = DataGridView1.Item(9, i).Value
    frmDisplayLockerInfo.TextBox8.Text = DataGridView1.Item(10, i).Value
    frmDisplayLockerInfo.TextBox9.Text = DataGridView1.Item(11, i).Value
    frmDisplayLockerInfo.TextBox10.Text = DataGridView1.Item(12, i).Value
    frmDisplayLockerInfo.TextBox11.Text = DataGridView1.Item(13, i).Value
    frmDisplayLockerInfo.TextBox14.Text = DataGridView1.Item(14, i).Value

End Sub

End Class

Recommended Answers

All 5 Replies

can you please tell me what is your prob , just posting your code is not sufficient to help you , explain your prob so that any one can help you.

Regards

i am using gridex and on cell click event display a form and all data are retrieve and displayed but some fields are blank and no data so runtime error dbnull and not converted into string.

The only line which is going to help you is "On Error Resume Next" .. since you have posted the code in whole, I am too lazy to imagine the whole form. So, just enter this code, after the line where you start 'Reading' the code. On Error Resume Next will 'jump to the next line' in case of an error.

On Error Resume Next will not help you. You need to know what line is generating the error. If you know the line then you can trace it back to a particular cell in the DataGridView and possibly back to the database table.

Have you tried something like below

frmDisplayLockerInfo.TextBox5.Text = DataGridView1.Item(7, i).Value & ""

I am not on a PC with a .NET environment so you may need to test it but it is the way I usually address this problem in VB

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.