有一个MSFLEXGRID表,用鼠标将第5行3列-10行3列选择,怎样用代码得出已选择的是几行几列?

解决方案 »

  1.   

    Option ExplicitDim m_lngRow As Long
    Dim m_lngCol As LongPrivate Sub Form_Load()
        Call InitGrid
    End SubPublic Sub InitGrid()
        Dim strTitle As String
        Dim i As Integer
        Dim k As Integer
        With MSFlexGrid1
            .AllowUserResizing = flexResizeBoth
            .Rows = 16
            .Cols = 7
            .RowHeightMin = 300
            strTitle = "<"
            For i = 1 To 6
                strTitle = strTitle & "|第" & i & "列"
            Next i
            strTitle = strTitle & ";"
            For i = 1 To 15
                strTitle = strTitle & "|第" & i & "行"
            Next i
            .FormatString = strTitle
            For i = 1 To 6
                .ColWidth(i) = 1200
            Next i
            For i = 1 To 15
                For k = 1 To 6
                    .TextMatrix(i, k) = "行" & i & "列" & k
                Next k
            Next i
        End With
    End SubPrivate Sub MSFlexGrid1_GotFocus()
        With MSFlexGrid1
            m_lngRow = .Row
            m_lngCol = .Col
        End With
    End SubPrivate Sub MSFlexGrid1_EnterCell()
        With MSFlexGrid1
            m_lngRow = .Row
            m_lngCol = .Col
        End With
    End SubPrivate Sub cmdOK_Click()
        With MSFlexGrid1
            MsgBox "选择的是从" & m_lngRow & "行" & m_lngCol & "列到" & .RowSel & "行" & .ColSel & "列"
        End With
    End Sub
      

  2.   

    MSFlexGrid1.Row 表示选择的第一行,
     MSFlexGrid1.RowSel 表示选择的最后一行。
      

  3.   

    通过Col和Row可以知道当前单元的行和列。例子: 
        Private Sub MSFlexGrid1_RowColChange() 
         Msg = "当前单元: " & Chr(64 + MSFlexGrid1.Col) 
         Msg = Msg & MSFlexGrid1.Row 
         Label1.Caption = Msg 
        End Sub 
         
        Private Sub MSFlexGrid1_SelChange() 
         Msg = "选中区域: " & Chr(64 + MSFlexGrid1.Col) 
         Msg = Msg & MSFlexGrid1.Row 
         Msg = Msg & ":" & Chr(64 + MSFlexGrid1.ColSel) 
         Msg = Msg & MSFlexGrid1.RowSel 
         Label2.Caption = Msg 
        End Sub 
      

  4.   

    Private Sub grdAccTime_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            m_lStartRow = grdAccTime.RowSel
            m_lStartCol = grdAccTime.ColSel
        End If
    End SubPrivate Sub grdAccTime_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim i, j As Long
        
        Dim lRow As Long
        Dim lCol As Long
        
        Dim lTempRow As Long
        Dim lTempCol As Long
        
        If (Button = vbLeftButton) And (chkAccTime.Enabled = True) Then
            lRow = grdAccTime.RowSel
            lCol = grdAccTime.ColSel
            If (lRow <> m_lStartRow) Or (lCol <> m_lStartCol) Then
                If lRow < m_lStartRow Then
                    lTempRow = m_lStartRow
                    m_lStartRow = lRow
                    lRow = lTempRow
                End If
                If lCol < m_lStartCol Then
                    lTempCol = m_lStartCol
                    m_lStartCol = lCol
                    lCol = lTempCol
                End If
            End If
        End If
    End Sub
      

  5.   

    用Anylib吧,完全可以解决你的问题,是自由界面和报表的完美解决方案。
    http://www.anylib.com