如题!在线等!
解决马上给分!

解决方案 »

  1.   

    '新增一列,比如第0列,单击时为选中状态,再单击则为没选中状态,然后循环mshflexgrid,根据是否选中状态来处理Private Sub HFlexgrid_KeyDown(KeyCode As Integer, Shift As Integer)
        with hflexgrid
            if trim(.textmatrix(.row,0))="" then
                .textmatrix(.row,0)="√"
            else
                .textmatrix(.row,0)=""
            end if
        end with
    End Subprivate sub command1_click()
        dim i as long
        with hflexgrid
            for i=1 to .rows-1
                if trim(.textmatrix(i,0))="√" then
                    '为“选中”时的处理
                  end if
            next i
        end with
    end sub
      

  2.   

    我要的是一个MSHFlexGrid表上随机选择单元格,不是单元行或单元列,用自定义的标识来好像不行吧
      

  3.   

    按住ctrl选择多个单元格,把下面代码直接拷贝,在窗体建一按钮Command1和一Grd1(MSHFlexGrid)就可以看效果了。Private m_sinCountCellWidth As Single   '所有列的宽度
    Private m_sinCountCellHeight As Single   '所有行的高度
    Private m_intSelect As Integer  '0 代表没有选中记录,大于0代表有选中记录数
    Private m_strSelect As String   '当为"0,"时代表没有选中记录,否则代表有选中记录Private Sub Command1_Click()
    Dim ss As String
    Dim i As Integer, j As Integer
    With Grd1    For i = 1 To .Rows - 1
            For j = 1 To .Cols - 1
                
                .Row = i
                .Col = j
                If .CellBackColor = vbBlue Then ss = ss & ",(" & i & ":" & j & ")"
            Next j
        Next
        If Len(ss) > 0 Then
            ss = Mid(ss, 2)
            MsgBox "你选择的记录为 " & ss, 64
        Else
            MsgBox "你没有选择记录!", 64
        End If
    End With
    End SubPrivate Sub Form_Load()
    Dim i, j As Integer
    m_intSelect = 0
    m_strSelect = "0"
    With Grd1
    .Rows = 10
    .Cols = 3
    For i = 1 To .Rows - 1
        For j = 1 To .Cols - 1
            .TextMatrix(i, j) = i
        Next
    Next
    .Row = 0
    For i = 0 To .Cols - 1
        .Col = i
        m_sinCountCellWidth = m_sinCountCellWidth + .CellWidth
    Next
    .Col = 0
    For i = 0 To .Rows - 1
        .Row = i
        m_sinCountCellHeight = m_sinCountCellHeight + .CellWidth
    Next
    End With
    End SubPrivate Sub Grd1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim i, j, k As Integer
    Dim StaRow, EndRow As Integer
    Dim XMax, YMax As Single
    Dim RowArray As Variant
    With Grd1
        k = .Row
        If .RowSel > .Row Then
            StaRow = .Row
            EndRow = .RowSel
        Else
            StaRow = .RowSel
            EndRow = .Row
        End If    XMax = .Left + m_sinCountCellWidth
        YMax = .Top + m_sinCountCellHeight    If x > XMax Or Shift <> 2 Then
            If m_strSelect <> "0" Then
                RowArray = Split(m_strSelect, ",")
                For i = 1 To UBound(RowArray)
                    'If i = 0 Then Exit For
                    .Row = RowArray(i)
                    For j = 1 To .Cols - 1
                        .Col = j
                        .CellBackColor = vbWhite
                    Next
                Next
            End If
            m_strSelect = "0"
            Exit Sub
        End If
        If Shift = 2 Then
            If .CellBackColor = vbBlue Then
                m_strSelect = Replace(m_strSelect, "," & .Row, "")
            Else
                m_strSelect = m_strSelect & "," & .Row
            End If
                If .CellBackColor = vbBlue Then
                    .CellBackColor = vbWhite
                Else
                    .CellBackColor = vbBlue            End If
            Exit Sub
         End If
    End With
    End Sub