Solved

VB6 Flexgrid Highlighting a row

Posted on 2007-11-29
10
2,814 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now