Solved

Highligth Flexgrid specific row during runtime!

Posted on 2008-06-17
9
679 Views
Last Modified: 2008-06-23
good afternoon...

hello experts!

i have some sort of problem..i have a flexgrid fill with records from the database..
what i wanted to do is when i click the command button, i want the selected row
to be highlighted (backcolor becomes yellow for ex). but the the backcolor should not be
fixed on the row..

thanks in advance experts!


game-master
0
Comment
Question by:game-master
[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
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21800515
Create 1 form with MSFlexGrid, set

Name = MSFlexGrid1
Cols = 3
Rows = 5
SelectionMode = 1 - flexSelectionByRow

Add to Command box with name Command1 and Command2.

Then copy and paste this code and test it.
Private Sub Command1_Click()
 
For i = 1 To 2
    MSFlexGrid1.Col = i
    MSFlexGrid1.CellBackColor = &HFFFF&
Next
End Sub
 
Private Sub Command2_Click()
For j = 1 To 4
    MSFlexGrid1.Row = j
    For i = 1 To 2
        MSFlexGrid1.Col = i
        MSFlexGrid1.CellBackColor = &H80000005
    Next
Next
End Sub
 
Private Sub Form_Load()
 
MSFlexGrid1.TextMatrix(0, 1) = "Column A"
MSFlexGrid1.TextMatrix(0, 2) = "Column B"
 
For i = 1 To 4
    MSFlexGrid1.TextMatrix(i, 1) = "ABC"
    MSFlexGrid1.TextMatrix(i, 2) = "123"
Next
 
End Sub
 
Private Sub MSFlexGrid1_LostFocus()
For j = 1 To 4
    MSFlexGrid1.Row = j
    For i = 1 To 2
        MSFlexGrid1.Col = i
        MSFlexGrid1.CellBackColor = &H80000005
    Next
Next
End Sub

Open in new window

0
 
LVL 13

Author Comment

by:game-master
ID: 21800966


good afternoon..

thank you..

but i wanted to that with only 1 command button...

if i click the command button, specific row will be highlighted
and the previously highlighted row will be unhighlighted..


game-master
0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21801032
You remove Command2 button, clear the code and paste the new one. How is it?
Dim currentrow As Integer
 
Private Sub Command1_Click()
currentrow = MSFlexGrid1.Row
 
For j = 1 To 4
    MSFlexGrid1.Row = j
    For i = 1 To 2
        MSFlexGrid1.Col = i
        MSFlexGrid1.CellBackColor = &H80000005
    Next
Next
 
MSFlexGrid1.Row = currentrow
For i = 1 To 2
    MSFlexGrid1.Col = i
    MSFlexGrid1.CellBackColor = &HFFFF&
Next
End Sub
 
Private Sub Form_Load()
 
MSFlexGrid1.TextMatrix(0, 1) = "Column A"
MSFlexGrid1.TextMatrix(0, 2) = "Column B"
 
For i = 1 To 4
    MSFlexGrid1.TextMatrix(i, 1) = "ABC"
    MSFlexGrid1.TextMatrix(i, 2) = "123"
Next
 
End Sub

Open in new window

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 13

Author Comment

by:game-master
ID: 21801244


i try to put ur code to the timer...
and the program, randomly select specific row..

but the specific was not unhighlighted...

game-master
0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21801256
What is the timer for? Can you give the code for the timer?
0
 
LVL 13

Author Comment

by:game-master
ID: 21801285


i use the timer to check the flexgrid the record was in there..
if the record is there then i need to highligth it...

something like this...

if matrix.textmatrix(1,0) = "Employee Name" then
  'unhighlight the previous row

  'unhighlight the row in witch the Employee Name is found...

end if


game-master
0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21801360
You mean you want to compare the data between in flexgrid and your record in database?
If i'm correct maybe you don't need to use timer, just use "For" looping.
0
 
LVL 13

Author Comment

by:game-master
ID: 21801414


i used timer because the data on the database
has been changing from time to time..

yes, im using "For Loop" on finding the record
on the flexgrid...

0
 
LVL 6

Accepted Solution

by:
psychic_zero earned 500 total points
ID: 21801515
Based on your explaination and my understanding, I've give you the sample code as below, hope this will help. I will going back to home right now and I will check back later when I arrived at home.
Private Sub Timer1_Timer()
 
'to unhighlight back all the data in the flexgrid
For j = 1 To MSFlexGrid1.Rows - 1  'number of flexgrid rows
    MSFlexGrid1.Row = j
    For i = 1 To MSFlexGrid1.Cols - 1   'number of flexgrid cols
        MSFlexGrid1.Col = i
        MSFlexGrid1.CellBackColor = &H80000005    'paint white color
    Next
Next
 
'check each row if the data exist in database
For j = 1 To MSFlexGrid1.Rows - 1  'number of flexgrid rows
    MSFlexGrid1.Row = j
 
    'let say column 1 is for employee name
    'if employee name found, than highlight with yellow, if not, then the background remain white
    If MSFlexGrid1.TextMatrix(j,1) = "Employee Name" then  'Employee name get from database
        For i = 1 To MSFlexGrid1.Cols - 1   'number of flexgrid cols
            MSFlexGrid1.Col = i
            MSFlexGrid1.CellBackColor = &HFFFF&   'highlight with yellow
        Next
    End If
 
Next
 
End Sub

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 127
Excel - Save a copy of work book 13 91
VBA Shell can't Find Word document 11 131
IF ELSE Statement in Excel Macro VBA 16 87
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

697 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