vb6cellmsflexgrid

Change cell background color without changing focus


On a form I have 4 MSFlexGrids.

The top grid contains dynamic data, which updates once in a while. The user can enter data in the cells of the 3 other grids.

The data which is used to fill the top grid is received via a Winsock control, processed, and then the results are written into the appropriate cells using .TextMatrix(intRow, intCol) = strData

This works fine. The data is updated flawlessly, and the user can enter his data into the other 3 grids without any problems.

The problem occurs when I want to change the background color of some cells in the top grid. On rare occasions the received data is very important, and the background color of the corresponding cells should change color.

I change the color of the cells with the following code:

With grd
  For lngRow = 1 To .Rows - 1
    'default background color
    lngBack = vbWhite
    'check for important values
    If Val(.TextMatrix(lngRow, 1)) >= lngMax Then
      'important color
      lngBack = &H3040FF
    End If
    'select whole row
    .Row = lngRow
    .Col = 0
    .RowSel = lngRow
    .ColSel = .Cols - 1
    'set the background color of the selected row
    .CellBackColor = lngBack
  Next lngRow
End With 'grd

The problem with this is that when the user is entering data in the other 3 grids, and the background color of a row in the top grid is changed, then the focus moves to the top grid, and the user has to enter his data anew in the grid where he was working.

Is it possible to change the background color of a cell or whole row in a MSFlexGrid without moving the focus to that grid?


Solution

  • So far I could not find a solution to the problem itself.

    I created a work around though :

    I created an enum containing a value for each grid:

    Public Enum ActiveGrid
      enuSystem = 0
      enuTel = 1
      enuRLN = 2
      enuRood = 3
      enuData = 4
      enuCircuit = 5
    End Enum
    

    Whenever a grid gets the focus I save the corresponding enum value in a form level variable. After coloring the required cells in the first grid I return the focus to the grid which last had it.

    The user is not editing in the grid itself, but in a textbox which is laid over the cell, so there is no real problem with the grid losing the focus.

    When you look closely though you see the focus leave and return quickly.

    For now I will accept this work around, and its minor glitches.

    Maybe in the future I can come up with a better solution, or anyone else has a better suggestion?