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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

msFlexGrid Highlight Not Working All the Time

Status
Not open for further replies.

erinallen

Programmer
May 13, 2002
66
US
Below is some code I have that isn't highlighting the row everytime. I don't know why. I want to highlight the row the user clicks on. I don't have the selectionmode set to row because I need to allow the users to double click on individual cells for data input.

Any help is very much appreciated.

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lIndex As Long
Dim lRow As Long
Dim CurrBackColor As Variant
Dim NewBackColor As Variant
Dim NewForeColor As Variant

With MSFlexGrid1
lRow = .RowSel
.Row = lRow
If lRow <> 0 Then
.Visible = False
.Col = 0: CurrBackColor = .CellBackColor
If CurrBackColor <> vbWindowBackground Then
NewBackColor = vbWindowBackground
NewForeColor = vbWindowText
Else
NewBackColor = vbHighlight
NewForeColor = vbWhite
End If
For lIndex = 0 To .Cols - 1
.Col = lIndex: .CellBackColor = NewBackColor: .CellForeColor = NewForeColor
Next
.Visible = True
End If
End With
 
My advice is to select by row. You can stil set the SelectionMode to ByRow and capture the row/column the user double-clicked on with MouseRow and MouseCol and set your edit textbox(s) accordingly:

Private Sub fg_DblClick()
MsgBox &quot;User Double-clicked Row &quot; & fg.MouseRow + fg.FixedRows & &quot;, Column: &quot; & fg.MouseCol + fg.FixedCols
End Sub

Mark
 
Why do I need the + fg.FixedRows?

So, I've changed my grid to select by row. I have highlight set to with focus, but when I click on a row, nothing is highlighted. What am I missing?
 

Come to think of it, you don't need the + fg.FixedRows or fg.FixedCols. You can check this by inserting MsgBox fg.TextMatrix(fg.MouseRow, fg.MouseCol) into the fg_dblclick event, and in the msgbox you should see the text in the cell. You do need them however to make sure the user didn't double click on the fixed columns or rows for editing.

I set my fg properties this way:

fg.HighLight = flexHighlightAlways
fg.SelectionMode = flexSelectionByRow
fg.FocusRect = flexFocusNone


Make sure you don't still have some other code executing that was &quot;unhighlighting&quot; the rows...



Mark
 
Thanks. It was my highlight set to focus that was causing the problem. I changed to always and it works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top