How to set the background of current active cell of MSFlexGrid control??

Gaoming_Fu
Gaoming_Fu used Ask the Experts™
on
Hi All:

I want to set the background color of any cell users clicked so that users feel any cells they clicked are highlighted, i.e., if users click cell of row 1 and col 1, this cell will be highlighted, then if users click cell of row 2 and col 2, this cell will be highlighted too, however, the cell of row 1 and col 1 must not be highlighted. Any time only the current active cell will have the background color that is different from all other cells.

Any help will be highly appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
try this... you will need to use styles and javascript...

<style>
TD.red {
     FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Arial,Helvetica; BACKGROUND-COLOR: #ff0000
}
TD.blue {
     FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Arial,Helvetica; BACKGROUND-COLOR: #0000ff
}
</style>
<script language="javascript">
function go(obj)
{
     obj.className="blue";
}
</script>
<TABLE>
<TR>
     <TD class=red onclick="go(this)">One</TD>
     <TD class=red onclick="go(this)">Two</TD>
     <TD class=red onclick="go(this)">Buckle My Shoe</TD>
</TR>
<TR>
     <TD class=red onclick="go(this)">Three </TD>
     <TD class=red onclick="go(this)">Four </TD>
     <TD class=red onclick="go(this)">Shut the Door</TD>
</TR>
<TR>
     <TD class=red onclick="go(this)">Five </TD>
     <TD class=red onclick="go(this)">Six</TD>
     <TD class=red onclick="go(this)">Pick up Stix</TD>
</TR>
<TR>
     <TD class=red onclick="go(this)">Seven </TD>
     <TD class=red onclick="go(this)">Eight</TD>
     <TD class=red onclick="go(this)">Stay UP Late</TD>
</TR>
<TR>
     <TD class=red onclick="go(this)">Nine </TD>
     <TD class=red onclick="go(this)">Ten </TD>
     <TD class=red onclick="go(this)">Do it all again</TD>
</TR>
</TABLE>
In VB, this is how I'd do it:

Private m_OldRow As Long
Private m_OldCol As Long

Private Sub MSFlexGrid1_EnterCell()
    Static bFromCode As Boolean
   
    Dim lRow As Long
    Dim lCol As Long
   
    With MSFlexGrid1
        If bFromCode = True Then
            Exit Sub
        End If
        bFromCode = True
        Debug.Print .Row & ":" & .Col
        lRow = .Row
        lCol = .Col
       
        '.RowSel = .Rows - 1
        '.ColSel = .Cols - 1
        If m_OldRow > 0 Then
            .Row = m_OldRow
            .Col = m_OldCol
            .CellBackColor = vbWhite
        End If

        .Row = lRow
        .Col = lCol
   
       
       
        '.Row = lRow
        '.Col = lCol
        '.RowSel = lRow
        '.ColSel = lCol
        .CellBackColor = vbRed
        m_OldRow = lRow
        m_OldCol = lCol
        bFromCode = False
    End With

End Sub

Author

Commented:
Hi twalgrave:

It worked, thanks a lot.

icredes, thanks a lot for for your comments too. I am using VBScript.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial