Solved

VB6 Flexgrid Highlighting a row

Posted on 2007-11-29
10
2,864 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
Technology Partners: 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 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

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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