前端之家收集整理的这篇文章主要介绍了
[VB.NET]datgridview问题,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
datgridview问题 我用splitcontainer把form隔开两部分,左边是datagridview控件只
显示id和name,右边是很多的text
Box,
显示详细
内容如性别,生日,电话等,如何编程实现选中左边一行,右边每个text
Box的
内容随之改变? __________________________________________________________________________ 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.Text
Box1.Text = Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(0).Value Me.Text
Box2.Text = Me.DataGridView1.Rows(Me.DataGridView1.SelectedCells(0).RowIndex).Cells(1).Value End If End Sub End Class __________________________________________________________________________ 在选中左边一行时触发事件,根据id到
数据库中把数据检索出来,分别填充到右边的text
Box中。 __________________________________________________________________________
原文链接:https://www.f2er.com/vb/263867.html