DataGrid 的鼠标点击

(一)DataGrid的MouseUp事件:

        Me.TextBox1.Text = DataGrid1(DataGrid1.CurrentRowIndex, 0)

        Me.TextBox2.Text = DataGrid1(DataGrid1.CurrentRowIndex, 1)

 

        If DataGrid1(DataGrid1.CurrentRowIndex, 2) = 1 Then

            Me.CheckBox1.Checked() = True

        Else

            Me.CheckBox1.Checked() = False

        End If

 

解释:点击DataGrid里的任意一行,其第0列显示在 TextBox1 里,第1列显示在 TextBox2 里。

      若第2列为判断“是/否”,则需要 CheckBox 控件,如果数据库中为“0”(表示“否”),则 CheckBox 前不打对勾;如果数据库中为“1”(表示“是”),则 CheckBox 前不对勾。

----------------------

(二)DataGrid的CurrentCellChanged事件:

Public cOutID As String

cOutID = Me.DataGrid1.Item(Me.DataGrid1.CurrentRowIndex, 0)

Dim frm As 新窗口名

frm = New 新窗口名 

frm.Show()

―――――

对应的DataGrid的MouseUp事件里写:

Me.DataGrid1.Select(Me.DataGrid1.CurrentRowIndex)

―――――

在打开的新窗口的form的load里写:

DBcon.Open()

Dim strSql As String = "select 字段名 from TMMOutDetail,TMMCom where TMMOutDetail.cComID=TMMCom.cComID and cOutID= '" & cOutID & "'"

Dim adt As New OleDbDataAdapter(strSql, DBcon)

ds.Clear()

adt.Fill(ds)

DataGrid1.DataSource = ds.Tables(0)

DBcon.Close

解释:点击DataGrid里的某一行,对应在新窗口里显示该行的信息。

原文地址:https://www.cnblogs.com/sishierfei/p/1610385.html