在所显示的datagrid数据中,选择一行数据,并让这行数据显示在各自的文本框中。
比如:datagrid中有姓名,年龄两个字段,选择任何一行后,在文本框中显示出姓名和年龄来。谢谢!
Dim b As DateTime
Dim c As String
Dim d As String
Dim f As String
Dim g As String
Dim h As String
Dim i As String
Dim j As String
Dim k As String
Dim cmd As New SqlCommand("select 计时工资 where 编号='" & DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0) & "'", conStr)
b = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 1)
c = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 2)
d = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3)
f = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 4)
g = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 5)
i = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 7)
j = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 8)
k = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 9)
h = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 11)
datetimepicker1.Text = b
textbox1.Text = c
combobox1.Text = d
combobox2.Text = f
combobox3.Text = g
TextBox2.Text = i
textbox3.Text = j
textbox4.Text = k
textbox5.Text = h
类似这样的 只要把表名和字段自己改下就OK了
谢谢了!chen5322.
这几天没人回答我自己也实现了,和你的不太一样,不过原理是一样的,都用到了DataGrid1.CurrentCell.RowNumber
Dim strsql As String = "select * from person"
Dim ds As New DataSet
ds = DB.RunSelectSQL(strsql)
Dim index As Integer = 0
If index <> Me.DataGrid1.CurrentCell.RowNumber Then
index = Me.DataGrid1.CurrentCell.RowNumber
Dim row As DataRow = ds.Tables(0).Rows(index)
Me.txtname.Text = row("name")
Me.txtage.Text = row("age")
共同学习!!