MSHFlexGrid1使用技巧(一)[如何让MSHFlexGrid只能被选中一行]

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

Option Explicit
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
.SelectionMode = flexSelectionByRow
.BackColorSel = vbGreen
.ForeColorSel = vbRed
End With
End Sub
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    With MSHFlexGrid1
     .Row = .MouseRow
          .Col = 0
        .ColSel = .Cols - 1
    End With
End Sub

原文地址:https://www.cnblogs.com/fengju/p/6336377.html