谢谢
在线等待
立即送分

解决方案 »

  1.   

    不是有ColSel、RowSel 属性吗ColSel — 为一定范围的单元格返回或设置的起始列和或终止列。RowSel — 为一定范围的单元格返回或设置的起始行和或终止行。
      

  2.   


    但是rowsel只是shift选中的最后一行的行号啊
      

  3.   

    在MouseDow事件中进行判断Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        Debug.Print MSFlexGrid1.Row & "行"    If Shift = 1 Then'按下了SHIFT键时
            Debug.Print MSFlexGrid1.RowSel & "选中行"
        End If
    End Sub
      

  4.   

    定义模块级变量:
    Private m_SelRow As Integer '单击时选中的行号
    Private m_ShiftSelRow As Integer '单击SHIFT同时选中的行号分别记录对应的值:
    Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Shift = 0 Then '未选中SHIFT的情况
            m_SelRow = MSFlexGrid1.Row
        Else
            m_ShiftSelRow = MSFlexGrid1.Row
        End If
    End Sub
      

  5.   

    啊九 我想这段代码应该写在mouseup事件中把.
    Private Sub MSHFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Text1.Text = MSHFlexGrid1.RowSel
    End Sub
      

  6.   

    Sorry,刚才写错了一点,应该是:Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Shift = 0 Then '未选中SHIFT的情况
            m_SelRow = MSFlexGrid1.Row 
            m_ShiftSelRow = 0 '清空值
        Else
            m_ShiftSelRow =MSFlexGrid1.RowSel 
        End If
    End Sub取得两个值后,通过取得两个数之间的数值可确定选中的行号
    测试:
    Private Sub Command1_Click()
        Dim intI As Integer
        Dim aArray() As Integer
        
        ReDim aArray(Abs(m_ShiftSelRow - m_SelRow)) As Integer '定义动态数组以记录选中的行数
        
        If m_ShiftSelRow > m_SelRow Then
            For intI = 0 To Abs(m_ShiftSelRow - m_SelRow)
                aArray(intI) = m_SelRow + intI
            Next
        Else
            For intI = 0 To Abs(m_ShiftSelRow - m_SelRow)
                aArray(intI) = m_ShiftSelRow + intI
            Next
        End If    
    End Sub
      

  7.   

    用动态数组来保存取得的行号,我已经测试成功了取得后可用UBound(aArray)取得对应动态数组中元素的个数,用:
    Debug.Print aArray(intI)在即时窗口中就可以看到取得的结果