Solved

VB6 Flexgrid Highlighting a row

Posted on 2007-11-29
10
2,823 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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