datagrid1和mshflexgrid1的 焦点怎样自动跟踪指定的行位置呢如怎样跟踪存在字符的最后字段的开始位置上。ABCDE
1
22
3358
55442
48413 这里E字段为按顺序最后字段,E字段的开始位置为2 ,focus焦点处于E字段的2的开始位置上。这个怎么做呢。

解决方案 »

  1.   


     mshflexgrid 和datagrid都有 object.Focus 这样焦点。
       焦点方式为按行显示焦点
      

  2.   

    Private Sub Form_Load()
        Dim i As Integer
        Dim j As Integer
        Dim aryA() As String    aryA = Split("1,22,3358,55442,48413", ",")
        With MSFlexGrid1
            .Rows = 6
            .Cols = 6        For i = 1 To UBound(aryA) + 1
                .Row = i
                For j = 1 To Len(aryA(i - 1))
                    .Col = j
                    .Text = Mid(aryA(i - 1), j, 1)
                Next j
            Next i
        End WithEnd SubPrivate Sub Command1_Click()
        Dim i As Integer
        Dim j As Integer
        
        With MSFlexGrid1
            .Col = .Cols - 1
            For i = 1 To .Rows - 1
                .Row = i
                If .Text <> "" Then
    '                .CellBackColor = vbRed
                    .SetFocus
                    Exit For
                End If
            Next i
        End With
        
    End Sub
      

  3.   

    焦点不可能按行,颜色可以Private Sub Form_Load()
        Dim i As Integer
        Dim j As Integer
        Dim aryA() As String    aryA = Split("1,22,3358,55442,48413", ",")
        With MSFlexGrid1
            .Rows = 6
            .Cols = 6        For i = 1 To UBound(aryA) + 1
                .Row = i
                For j = 1 To Len(aryA(i - 1))
                    .Col = j
                    .Text = Mid(aryA(i - 1), j, 1)
                Next j
            Next i
        End WithEnd SubPrivate Sub Command1_Click()
        Dim i As Integer
        Dim j As Integer
        
        With MSFlexGrid1
            .Col = .Cols - 1
            For i = 1 To .Rows - 1
                .Row = i
                If .Text <> "" Then
    '                .CellBackColor = vbRed
                    Call set_row_color(MSFlexGrid1, .Row)
                    .SetFocus
                    Exit For
                End If
            Next i
        End With
        
    End SubPrivate Sub set_row_color(ByRef objMSFlexGrid As MSFlexGrid, ByVal lngRow As Long)
        Dim j As Integer    With objMSFlexGrid
            .Row = lngRow
            For j = 1 To .Cols - 1
                .Col = j
                .CellBackColor = vbRed
            Next j
        End WithEnd Sub