?
Solved

Flexgrid Row Highlighting

Posted on 2003-02-23
5
Medium Priority
?
571 Views
Last Modified: 2007-12-19
Would be grateful if someone could pls provide some working code for the following:

1. whenever a user clicks in an MS Flexgrid, to highlight the entire row (yellow)

2. the value in Column 3 of that row gets shown in a textbox on the form

Thanks!
0
Comment
Question by:DoctorNash
[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
  • 2
5 Comments
 
LVL 2

Expert Comment

by:IeuanJ
ID: 8006974
The highlight can be set via the properties ForeColorSel & BackColorSel.  Alternatively like this (although this will leave highlighted after selection is removed unless you trap it) -

Private Sub MSFlexGrid1_Click()
  For i = 0 To MSFlexGrid1.Cols - 1
    MSFlexGrid1.BackColor = vbYellow
  Next i
End Sub

The text box can be populated as such -

Private Sub MSFlexGrid1_Click()
  Text1.Text = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)
End Sub
0
 

Author Comment

by:DoctorNash
ID: 8012071
leuanJ,
Thanks for your reply. The second part (text box population) works fine, but your 'highlighting' code results in the WHOLE TABLE being painted yellow. Was only looking for the selected row to be highlighted. I resolved that myself, but as you say, now I need code that will remove the previously hightlighted row when a new row is highlighted by the user.
0
 
LVL 2

Accepted Solution

by:
IeuanJ earned 100 total points
ID: 8015694
Apologies for that, I used the wrong backcolor value, should have been cellbackcolor.  Anyway the below code will return all cellbackcolors to white before highlighting the row you click, this does this every time so creates the illusion of highlighting one row at a time.

Private Sub MSFlexGrid1_Click()
  Dim originalRow As Integer
  Dim originalCol As Integer
  Dim i As Integer
  Dim j As Integer
 
  originalRow = MSFlexGrid1.Row
  originalCol = MSFlexGrid1.Col
 
  For i = 0 To MSFlexGrid1.Rows - 1
    MSFlexGrid1.Row = i
    For j = 0 To MSFlexGrid1.Cols - 1
      MSFlexGrid1.Col = j
      MSFlexGrid1.CellBackColor = vbWhite
    Next j
  Next i

  MSFlexGrid1.Row = originalRow
 
  MSFlexGrid1.BackColor = vbWhite
  For i = 0 To MSFlexGrid1.Cols - 1
    MSFlexGrid1.Col = i
    MSFlexGrid1.CellBackColor = vbYellow
  Next i
 
  MSFlexGrid1.Col = originalCol
End Sub

Remember this will change the properties of any fixedrows & cols as well so if you have these then alter the loops accordingly.

I still think your best option would be to change the backcolorsel value in the flexgrid properties.
0
 

Author Comment

by:DoctorNash
ID: 8030076
Leuanj,
Brilliant! Works a treat. Your code has actually given me a few other ideas as well, which I played around with last night - you've helped me along the way to getting a better understanding of how this component works. Thanks - here are your well deserved points.
0
 
LVL 2

Expert Comment

by:IeuanJ
ID: 8031905
your welcome and thanks very much, I've found this object to be a very good and versitile one myself although extrememly poorly documented and not that widely used.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

752 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