我这么写的
Private Sub Command2_Click()
    aaaa = True
    fg.Row = 3
    fg.Col = 1
    fg.CellBackColor = vbRed
    fg.Col = 2
    fg.CellBackColor = vbRed
    fg.Col = 1
    aaaa = False
End SubPrivate Sub fg_LeaveCell()
   If aaaa = False Then
       fg.CellBackColor = vbWhite
   End If
End Sub可是当焦点移动到其他行时,刚才指定颜色的那行却变不回白色了.请问这段代码应该怎么写?

解决方案 »

  1.   

    '参考如下Private Sub hflexgrid_EnterCell()
      '单击某一单元时,改变该行颜色
      Dim i_Col As Integer
      Dim c_col As Integer
      c_col = Hflexgrid.Col
      If c_col > 0 Then
         For i_Col = 0 To Hflexgrid.Cols - 1
             Hflexgrid.Col = i_Col
             Hflexgrid.CellBackColor = &HFFFFC0
         Next i_Col
         Hflexgrid.Col = c_col
      End If
    End SubPrivate Sub hflexgrid_LeaveCell()
      '当某一行失去焦点时,改变该行颜色
      Dim i_Col As Integer
      Dim c_col As Integer
      c_col = Hflexgrid.Col
      For i_Col = 0 To Hflexgrid.Cols - 1
          Hflexgrid.Col = i_Col
          Hflexgrid.CellBackColor = vbWhite
      Next i_Col
      Hflexgrid.Col = c_col
    End Sub
      

  2.   

    在声明中加上:option explicit试试,可能有些变量没有声明
      

  3.   

    哦.可以了,刚才因为我用的是MS FlexGrid.
    用MSFlexGrid应该怎么写啊?