我有一个datagrid
,我希望所选行中的数据显示在textbox
中。我正在使用.NET 2003
。我发现的只是datagridview
的解决方案。我尝试了此代码以及SelectedRows
,但datagrid
中没有该函数。
Private Sub Grid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid2.SelectedIndexChanged
Dim i, j As Integer
i = Grid2.CurrentRow.Index
TextBox1.Text = Grid2.Item(0, i).Value
TextBox2.Text = Grid2.Item(1, i).Value
TextBox3.Text = Grid2.Item(2, i).Value
TextBox4.Text = Grid2.Item(3, i).Value
End Sub
答案 0 :(得分:1)
试试这个:
Private Sub Grid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid2.SelectedIndexChanged
TextBox1.Text = Grid2.SelectedItem.Cells(0).Text
TextBox2.Text = Grid2.SelectedItem.Cells(1).Text
TextBox3.Text = Grid2.SelectedItem.Cells(2).Text
TextBox4.Text = Grid2.SelectedItem.Cells(3).Text
End Sub