datgridview问题
我用splitcontainer把form隔开两部分,左边是datagridview控件只显示id和name,右边是很多的textbox,显示详细内容如性别,生日,电话等,如何编程实现选中左边一行,右边每个textbox的内容随之改变?
[解决办法]
Imports System
Imports System.Data.OleDb
Public Class Form1
Dim conn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim flag As Boolean
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn = New OleDbConnection( "Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\data.mdb ")
conn.Open()
da = New OleDbDataAdapter( "SELECT * FROM 表1 ", conn)
ds = New DataSet
da.Fill(ds)
conn.Close()
Me.DataGridView1.DataSource = ds.Tables(0)
flag = True
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If flag Then
Me.TextBox1.Text = Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(0).Value
Me.TextBox2.Text = Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(1).Value
End If
End Sub
End Class