-
Sep 7th, 2012, 09:29 AM
#1
Thread Starter
Member
How to highlight a record in a MSHFlexGrid?
I have a MSHFlexGird (fgdCompany) and a search command. When the user enters the search data into "txtSearch", the command should search for the data and show it to the user by :
Highlighting the record in the MSHFlexGrid
-OR-
By bringing the row that contains the searched data to the top of the MSHFlexGrid.
The code that I am using is given below. The search function works perfectly. Only thing is I can't make the record that contains the searched data be highlighted so that the user knows in which record the data that was search data is present. Can anybody could give me the code to highlight the record found in any of the two methods given above (preferably the first option).
Code:
Dim xString As String, xRow As Integer, xNext As Integer
xString = txtSearch.Text
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
xRow = fgdCompany.Row
If xString = fgdCompany.TextMatrix(xRow, 1) Then 'Assuming that the string to be searched is in coloumn 1...
myRow = fgdCompany.Row
Exit For
End If
Next xNext
-
Sep 7th, 2012, 09:33 AM
#2
Re: How to highlight a record in a MSHFlexGrid?
I just did on your original post......let me know if that works......
-
Sep 7th, 2012, 09:42 AM
#3
Thread Starter
Member
Re: How to highlight a record in a MSHFlexGrid?
Originally Posted by SamOscarBrown
I just did on your original post......let me know if that works......
hi. When I run the program it gives the error "Next without For" and when clicked debug, it highlights the line "Next x"
-
Sep 7th, 2012, 10:10 AM
#4
Re: How to highlight a record in a MSHFlexGrid?
argh....hate copy-paste....(change all MSHFlexgrid1 to MSFlexgrid1 (my code uses MSHF....)
here:
For X = 0 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Col = X
For Y = 1 To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Row = Y
MSHFlexGrid1.CellBackColor = vbYellow 'assuming vbYellow is original BG color
Next Y
Next X
For Z = 0 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Col = Z
MSHFlexGrid1.Row = rownumber1
MSHFlexGrid1.CellBackColor = vbGreen
Next Z
-
Sep 7th, 2012, 10:14 AM
#5
Thread Starter
Member
Re: How to highlight a record in a MSHFlexGrid?
I'm currently using this code.
Code:
xString = txtSearch.Text
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
xRow = fgdCompany.Row
If xString = fgdCompany.TextMatrix(xRow, 1) Then
myRow = fgdCompany.Row
fgdCompany.TopRow = myRow
Exit For
End If
Next xNext
Can you please say me where I should insert the code you have given above.
(fgdCompany is the name of my MSHFlexGrid)
And how do I find out my original BG color?
Last edited by Skate Bart; Sep 7th, 2012 at 10:18 AM.
-
Sep 7th, 2012, 10:51 AM
#6
Re: How to highlight a record in a MSHFlexGrid?
sorry...change all MSFLEXGrid1's to "fgdCompany"
-
Sep 7th, 2012, 10:24 AM
#7
Thread Starter
Member
Re: How to highlight a record in a MSHFlexGrid?
Originally Posted by SamOscarBrown
argh....hate copy-paste....(change all MSHFlexgrid1 to MSFlexgrid1 (my code uses MSHF....)
here:
For X = 0 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Col = X
For Y = 1 To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Row = Y
MSHFlexGrid1.CellBackColor = vbYellow 'assuming vbYellow is original BG color
Next Y
Next X
For Z = 0 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Col = Z
MSHFlexGrid1.Row = rownumber1
MSHFlexGrid1.CellBackColor = vbGreen
Next Z
OMG OMG!!! It worked. I tweaked the code a little bit with the one you gave above and it works perfectly.
But the problem is, it only highlights the first column of the row that the searched data was found. I want it to highlight the whole row.
Any ideas?
Here's the Code I'm using now :
Code:
xString = txtSearch.Text
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
xRow = fgdCompany.Row
If xString = fgdCompany.TextMatrix(xRow, 1) Then
myRow = fgdCompany.Row
fgdCompany.RowSel = myRow
fgdCompany.CellBackColor = vbGreen
Exit For
End If
Next xNext
-
Sep 7th, 2012, 10:50 AM
#8
Re: How to highlight a record in a MSHFlexGrid?
Create a private subroutine (I called my HIGHLIGHTING). Call that function after this line: fgdCompany.TopRow = myRow.
To find the original backcolor.....look at the properties of your MSFlexgrid, and find the one called 'backcolor'. You can use the hexidecimal to reset, or RGB equivalent, or VBs Constants.
I use a free application (colorpicker) to find ANY RGB color.....to make it easy, set your grid's backcolor at initialization to someting like vbWhite, then you can use another VB Constant (liek vbGreen) to highlight
xString = txtSearch.Text
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
xRow = fgdCompany.Row
If xString = fgdCompany.TextMatrix(xRow, 1) Then
myRow = fgdCompany.Row
fgdCompany.TopRow = myRow
CALL HIGHLIGHTING
Exit For
End If
Next xNext
Private Sub highlighting()
For X = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = X
For Y = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.Row = Y
MSFlexGrid1.CellBackColor = vbYellow 'assuming vbYellow is original BG color
Next Y
Next X
For Z = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = Z
MSFlexGrid1.Row = rownumber1
MSFlexGrid1.CellBackColor = vbGreen
Next Z
END SUB
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|