Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFLEXGRID 1

Status
Not open for further replies.

Normally

IS-IT--Management
May 13, 2008
22
BB
I populated flexgrid with data. I can hilight a row when mouse goes over the grid. How can i get hilighted row turned off when i leave the flexgrid?
 

Code:
With MSFLEXGRID
  For r = 1 To .Rows - 1
    .Row = r
    For c = 1 To .Cols - 1
      .Col = c
      .CellBackColor = vbWhite
    Next c
  Next r
End With

Have fun.

---- Andy
 
As the mouse leaves the flegrid the hilighted row shuold be like all other rows.
 
here is my code

Private Sub Grid_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Grid.MouseRow <> RowActual Then
ChangeGridColor RowActual, 0
RowActual = Grid.MouseRow
HiRow = Grid.MouseRow
ChangeGridColor RowActual, 1
Text1 = "I'm over row " & RowActual
End If
End Sub

Private Sub ChangeGridColor(RowNum As Integer, Num As Integer)
Grid.Row = RowNum
Grid.Redraw = False
Select Case Num
Case 0
For c = 0 To Grid.Cols - 1
Grid.Col = c
Grid.CellBackColor = Grid.BackColorFixed
Grid.CellForeColor = Grid.ForeColorFixed
Next c
Case 1
For c = 0 To Grid.Cols - 1
Grid.Col = c
Grid.CellBackColor = Grid.BackColorSel
Grid.CellForeColor = Grid.ForeColorSel
Next c
End Select
Grid.Redraw = True
End Sub

As Grid looses focus I want hilighted row to return to normal.
 
The grid is not getting focus with the MouseMove event, so using the LostFocus event won't work either.

Here's one work around leaving a small border of the form around the flexgrid

Note the use of Option Explicit (very good coding practise to get into)

Code:
Option Explicit

Private ChangedGrid  As Boolean
Private RowActual    As Integer
Private HiRow        As Integer

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim r As Integer
Dim c As Integer

If ChangedGrid Then
   ChangedGrid = False
   
   With Grid
        For r = 1 To .Rows - 1
           .Row = r
            For c = 1 To .Cols - 1
               .Col = c
               .CellBackColor = vbWhite
            Next c
        Next r
   End With
End If
End Sub

Private Sub Grid_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Grid.MouseRow <> RowActual Then
      ChangeGridColor RowActual, 0
      RowActual = Grid.MouseRow
      HiRow = Grid.MouseRow
      ChangeGridColor RowActual, 1
      Text1 = "I'm over row " & RowActual
      [COLOR=red]ChangedGrid = True[/color]
   End If
End Sub

Private Sub ChangeGridColor(RowNum As Integer, Num As Integer)
Dim c As Integer

   Grid.Row = RowNum
   Grid.Redraw = False
   Select Case Num
      Case 0
         For c = 0 To Grid.Cols - 1
            Grid.Col = c
            Grid.CellBackColor = Grid.BackColorFixed
            Grid.CellForeColor = Grid.ForeColorFixed
         Next c
      Case 1
         For c = 0 To Grid.Cols - 1
            Grid.Col = c
            Grid.CellBackColor = Grid.BackColorSel
            Grid.CellForeColor = Grid.ForeColorSel
         Next c
   End Select
   Grid.Redraw = True
End Sub
 

How about this:
(modified code, not tested)
Code:
Option Explicit

Private ChangedGrid  As Boolean
Private RowActual    As Integer
Private HiRow        As Integer

Private Sub Form_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)

If ChangedGrid Then
   ChangedGrid = False
   [blue]ChangeGridColor RowActual, 0[/blue]
End If

End Sub

Private Sub Grid_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
   If Grid.MouseRow <> RowActual Then
      ChangeGridColor RowActual, 0
      RowActual = Grid.MouseRow
      HiRow = Grid.MouseRow
      ChangeGridColor RowActual, 1
      Text1 = "I'm over row " & RowActual
      ChangedGrid = True
   End If
End Sub

Private Sub ChangeGridColor(RowNum As Integer, Num As Integer)
Dim c As Integer

[blue]With Grid[/blue]
   .Row = RowNum
   .Redraw = False
   Select Case Num
      Case 0
         For c = 0 To .Cols - 1
            .Col = c
            .CellBackColor = .BackColorFixed
            .CellForeColor = .ForeColorFixed
         Next c
      Case 1
         For c = 0 To .Cols - 1
            .Col = c
            .CellBackColor = .BackColorSel
            .CellForeColor = .ForeColorSel
         Next c
   End Select
   .Redraw = True
[blue]End With[/blue]

End Sub
And I totally agree with using Option Explicit


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top