Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 Flexgrid Highlighting a row

Posted on 2007-11-29
10
Medium Priority
?
2,900 Views
Last Modified: 2013-12-25
I use flexgrids alot but I often have trouble keeping the highlight on a selected row.  When I select the row and then set a value of the flexgrid.col to get the data in a cell in the row I have slected, the highlight disappears.

How can I get the data from the cell without unhighlighting the row?
0
Comment
Question by:keymac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:gpizzuto
ID: 20380422
set the selectionmode to column
0
 
LVL 8

Expert Comment

by:gpizzuto
ID: 20380424
pardon, to row
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20381520
flexgrid1.SelectionMode = flexSelectionByRow
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20381829
check whether this helps

Private Sub MSFlexGrid1_Click()
MSFlexGrid1.SelectionMode = flexSelectionByRow
Dim selectedrow As Integer
selectedrow = MSFlexGrid1.Row
For i = 1 To MSFlexGrid1.Rows - 1
For j = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Row = i
MSFlexGrid1.Col = j
MSFlexGrid1.CellBackColor = vbWhite
Next
Next
MSFlexGrid1.Row = selectedrow
For j = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = j
MSFlexGrid1.CellBackColor = vbRed
Next
End Sub
0
 

Author Comment

by:keymac
ID: 20387484
Yeah I had coded a similar answer, ie setting the backgrounds to white with black foregrounds and setting the selected row backgrounds to blue and foreground to white.  But I hoped that there would be a better way than going through the all the rows in the flexgrid to set the default white background - black foreground..

I also created a procedure in globals module as per
Private sub fgTable_click()
     highlight_selected_row (fgTable, fgTable.row)
end sub
 
 
public sub highlight_selected_row(fg as MSflexgrid, dblRow as double)
    Dim dblX as double
    Dim iY as integer
 
    for dblX = 1 to fg.rows - 1
        fg.row = dblX
        for iY = 1 to fg.cols - 1
            fg.col = iY
            fg.cellbackcolor = vbWhite
            fg.cellforecolor = vbBlack
        next iY
    next dblx
 
    fg.row = dblRow
    for iY = 1 to fg.cols - 1
        fg.col = iY
        fg.cellbackcolor = vbBlue
        fg.cellforecolor = vbWhite
    next iY
end sub

Open in new window

0
 
LVL 2

Expert Comment

by:tonym001
ID: 20390092

Private Sub Form_Load()
MSFlexGrid1.SelectionMode = flexSelectionByRow
MSFlexGrid1.HighLight = flexHighlightAlways
End Sub
0
 

Author Comment

by:keymac
ID: 20390604
Private Sub Form_Load()
MSFlexGrid1.SelectionMode = flexSelectionByRow
MSFlexGrid1.HighLight = flexHighlightAlways
End Sub

This doesn't work once you set the grid column
0
 
LVL 2

Expert Comment

by:tonym001
ID: 20394492
Dim strValue As String
    'get the value of the column in the selected row

    strValue = .TextMatrix(.RowSel, 0)
0
 
LVL 2

Accepted Solution

by:
tonym001 earned 500 total points
ID: 20394505
Sorry I sent that before I intended to

If you use the .Textmatrix property of the grid instead of setting the .Row and .Col values you can pick up the data values from the grid without affecting the focus. For instance,

Dim strValue As String
If Grid.RowSel = 0 Then
       'get the value of the first column in the selected row
        strValue = Grid.TextMatrix(Grid.RowSel, 0)
End If
0
 

Author Closing Comment

by:keymac
ID: 31411848
Excellent just exactly what I wanted
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question