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
焦点不可能按行,颜色可以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
mshflexgrid 和datagrid都有 object.Focus 这样焦点。
焦点方式为按行显示焦点
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
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