• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

changing cellbackcolor when hitting the enter key in msflexgrid - use for navigating

currently, I can navigate the grid using the enter key. What  I need is to change the cellbackcolor as I enter or get focus ont he cell then change it back to normal when it leaves.

I have not see any code yet that does this.

Thanks for your help
0
zachvaldez
Asked:
zachvaldez
  • 4
  • 2
2 Solutions
 
RimvisCommented:
Try this:

Option Explicit

Private Sub MSFlexGrid1_RowColChange()
    Dim x As Integer, y As Integer
    Dim i As Integer, j As Integer
    Static bLock As Boolean

    If bLock Then Exit Sub
   
    bLock = True
   
    'remember position
    x = MSFlexGrid1.Col
    y = MSFlexGrid1.Row

    'reset color
    For i = 1 To MSFlexGrid1.Rows - 1
        For j = 1 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = i
            MSFlexGrid1.Row = j
            MSFlexGrid1.CellBackColor = vbWhite
        Next j
    Next i

    'set background color
    MSFlexGrid1.Col = x
    MSFlexGrid1.Row = y
    MSFlexGrid1.CellBackColor = vbRed
   
    bLock = False
   
End Sub
0
 
zachvaldezAuthor Commented:
Getting i'nvalid column value error'

For i = 1 To MSFlexGrid1.Rows - 1
        For j = 1 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = i  >>>>>> error this point
            MSFlexGrid1.Row = j
            MSFlexGrid1.CellBackColor = vbWhite
        Next j
0
 
PePiCommented:
MSFlexGrid1.Col = j
MSFlexGrid1.Row = i

Rimvis got it backwards
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
zachvaldezAuthor Commented:
Yes! It changes the color of the cell  when you use the mouse but not when using the enter key..
0
 
zachvaldezAuthor Commented:
This caused it to flicker the form..
because it is going to every cell. in the grid.. Is it possible to just the single cell...? thanks

  For i = 1 To MSFlexGrid1.Rows - 1
        For j = 1 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = j
            MSFlexGrid1.row = i
            MSFlexGrid1.CellBackColor = vbWhite
      Next j
       
    Next i
0
 
RimvisCommented:
>> Rimvis got it backwards
Yes, dammit :o)

>>  Is it possible to just the single cell
I don't think it's possible

>>  This caused it to flicker the form
Try this to remove flickering

    MSFlexGrid1.Redraw = False

    'reset color
    For i = 1 To MSFlexGrid1.Rows - 1
        For j = 1 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = j
            MSFlexGrid1.Row = i
            MSFlexGrid1.CellBackColor = vbWhite
        Next j
    Next i

    MSFlexGrid1.Redraw = True
0
 
zachvaldezAuthor Commented:
IT worked!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now