日期:2013-11-26  浏览次数:20513 次

MSHFlexGrid控件点击时可以选中多行,但有时我们需要仅仅选中一行,有一个小技巧:



Option Explicit
Dim CURRENTROW As Integer
Private Sub Form_Load()
Dim i As Integer, j As Integer
With MSHFlexGrid1
.Rows = 10
.Cols = 4
For i = 1 To 9
.TextMatrix(i, 0) = "第 " & i & " 行"
For j = 1 To 3
.TextMatrix(0, j) = "第 " & j & " 列"
.TextMatrix(i, j) = i & "," & j
Next
Next
End With
End Sub
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
With MSHFlexGrid1
.Row = .MouseRow
CURRENTROW = .Row
.Col = 0
.ColSel = .Cols - 1
End With
End Sub
Private Sub MSHFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
With MSHFlexGrid1
.RowSel = CURRENTROW
.ColSel = .Cols - 1
End With
End Sub