16,722
社区成员




Public Class Form1
Dim msdown As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 1 To 10
DataGridView1.Rows.Add(i * 1, i * 2, i * 3, i * 4, i * 5, i * 6)
Next
End Sub
Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
msdown = True
End Sub
Private Sub DataGridView1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseUp
If msdown Then
'DataGridView1.CurrentCell = DataGridView1.SelectedCells(DataGridView1.SelectedCells.Count - 1)
msdown = False
End If
End Sub
Private Sub DataGridView1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(DataGridView1.CurrentCell.Value)
End Sub
Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp
' DataGridView1.CurrentCell = DataGridView1.SelectedCells(DataGridView1.SelectedCells.Count - 1)
End Sub
Private Sub DataGridView1_CellMouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseMove
If msdown Then
If DataGridView1.SelectedCells(0) IsNot Nothing Then
' DataGridView1.CurrentCell = DataGridView1.SelectedCells(DataGridView1.SelectedCells.Count - 1)
TextBox1.Text = DataGridView1.SelectedCells(DataGridView1.SelectedCells.Count - 1).Value
' TextBox2.Text = DataGridView1.CurrentCell.Value
End If
End If
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
DataGridView1.CurrentCell = DataGridView1.SelectedCells(DataGridView1.SelectedCells.Count - 1)
TextBox2.Text = DataGridView1.CurrentCell.Value
End Sub
End Class