Solved

VB6 Flexgrid Highlighting a row

Posted on 2007-11-29
10
2,805 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 125 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now