另外,我们如果想要保留MSFlexGrid可以整列整行选取,而且又可以更动MSFlexGrid最 上与最左边的固定列之Title,我的做法是,在MSFlexGrid上MouseUp时来判定Mouse所在 的Col与Row,如果MouseCol=0 or MouseRow = 0代表是在FixedCol/FixedRow 上按下 Mouse,如果按的是右键表示要修改FixCol或FixRow的Title,如果是左键,那不做任何 处理,此时,如果AllowBigSelection=True时,则会选取整行或整列。' '以下在Form需一个MSFlexGrid, 一个TextBox Option Explicit Private OldText As String Private ColSelect() As Boolean Private SaveCellBkColor As Long
Private Sub Form_Load() Text1.Visible = False Me.Show With MSFlexGrid1 .Cols = 5 .Rows = 15 ReDim ColSelect(1 To .Cols - 1) SaveCellBkColor = .CellBackColor Call InitGrid .AllowBigSelection = True .FillStyle = flexFillRepeat '.AllowUserResizing = True '请事先设好 End With End Sub
Private Sub InitGrid() Dim i As Long With MSFlexGrid1 .Row = 0 For i = 1 To .Cols - 1 .Col = i: .Text = "Col" + Format(i, "00") '若Cols超出99,则修改Format Next '的格式 End With With MSFlexGrid1 .Col = 0 For i = 1 To .Rows - 1 .Row = i: .Text = i Next End With 'Dim width5 As Long 'With MSFlexGrid1 ' width5 = .Width \ .Cols ' For i = 0 To .Cols - 1 ' .ColWidth(i) = width5 ' Next 'End With End Sub Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) Dim inMostLeft As Boolean Dim inMostTop As Boolean
Call ProcMultiColSel(Shift) With MSFlexGrid1 If Button = vbKeyRButton Then '按mouse 右键且位於最上列/最左行则是更动title If .MouseCol = 0 Or .MouseRow = 0 Then Call toEditGrid(.MouseCol, .MouseRow) End If Else If Button = vbKeyLButton The