datagridview data to textbox
Hi i have problem in this code it says "Object reference not set to an instance of an object."
i have a textbox for search,a datagridview and 7 textboxes for the items info. if i type the word in search texboxes and the datagridview shows the match item but when i clicked the datagridview it shows the error..
Private Sub Supplies_RegularDataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Supplies_RegularDataGridView1.CellClick
Supplies_RegularDataGridView1.Rows(e.RowIndex).Selected = True
Dim i = Supplies_RegularDataGridView1.CurrentRow.Index
TextBox1.Text =开发者_JS百科 Supplies_RegularDataGridView1.Item(1, i).Value.ToString()
TextBox2.Text = Supplies_RegularDataGridView1.Item(2, i).Value.ToString()
TextBox3.Text = Supplies_RegularDataGridView1.Item(3, i).Value.ToString()
TextBox4.Text = Supplies_RegularDataGridView1.Item(4, i).Value.ToString()
TextBox5.Text = Supplies_RegularDataGridView1.Item(5, i).Value.ToString()
TextBox14.Text = Supplies_RegularDataGridView1.Item(6, i).Value.ToString()
TextBox6.Text = Supplies_RegularDataGridView1.Item(7, i).Value.ToString() =the error here
End Sub
Supplies_RegularDataGridView1.Item(7, i).Value
is null
in c# you may do the following:
Supplies_RegularDataGridView1.Item(7, i).Value!=null?Supplies_RegularDataGridView1.Item(7, i).Value:"";
try this code
Dim I%
DataGridView2.Item(0, I).Value = Text1.Text
DataGridView2.Item(1, I).Value = Text2.Text
DataGridView2.Item(2, I).Value = Text3.Text
DataGridView2.Item(3, I).Value = Text4.Text
DataGridView2.Item(4, I).Value = Text5.Text
精彩评论