|
-
Apr 19th, 2007, 03:16 PM
#1
Thread Starter
New Member
[RESOLVED] MSHFlexGrid - Set Selected Row
So I have found the MSHFlexGrid control. With some searching, I have found out how to bind it to a ADODB.Recordset and display the results on the form. I have also been able to create a text box, and when the user types in the text box, key through the grid to find those matching rows in the grid.
Here is the problem I am running into, and can't seem to find anywhere on the net. How do I programatically make the first row I come across the "Selected row"?
Code:
Dim iCounter as Long
If (Len(sString) = 0) Then
Me.flexGrid.row = 0
Else
For iCounter = 0 To (Me.flexGrid.Rows - 1) Step 1
If (Left(Me.flexGrid.TextMatrix(iCounter, iColumnNum), Len(sString)) = sString) Then
'The values match
Exit For
End If
Next iCounter
End If
The above code is in my Textbox.KeyUp event. I tried adding a line that says:
Me.flexGrid.Row = iCounter
but that didn't set the selected row like I hoped.
Is there a simple solution that I'm overlooking?
Currently debugging and building: VB6 SP6
-
Apr 19th, 2007, 03:33 PM
#2
Re: MSHFlexGrid - Set Selected Row
A Selected row is actually a Range of Cells.
Code:
With Me.flexGrid
.Row = iCounter 'sets the current row
.Col = .FixedCols 'sets the current col and start of range
.ColSel = .Cols - 1 'sets the end range
End With
-
Apr 19th, 2007, 03:45 PM
#3
Thread Starter
New Member
Re: MSHFlexGrid - Set Selected Row
brucevde - Thank you for the timely response!
The code you provided selects the columns for the row based on what was typed in, but if the first result found isn't on the screen, it doesn't bounce that row selected into the viewable set of records on the form. Is that a possibliity with this control?
For example, if I have the grid with 150 records in it, and only 15 are displayed on the screen at a time. If the user keys in something that matches record number 50, can I make it bump down so it display row 50 on the screen (preferably as the first in the list, but on the screen would be a bonus at this point). I tried setting all those that don't match to have a row height of 0, but for very big record sets, this can take quite a bit of time.
Currently debugging and building: VB6 SP6
-
Apr 19th, 2007, 05:18 PM
#4
Re: MSHFlexGrid - Set Selected Row
Use the TopRow property to scroll a row into view.
Code:
With Me.flexGrid
.Row = iCounter 'sets the current row
.Col = .FixedCols 'sets the current col and start of range
.ColSel = .Cols - 1 'sets the end range
.TopRow = .Row
End With
-
Apr 20th, 2007, 08:29 AM
#5
Thread Starter
New Member
Re: MSHFlexGrid - Set Selected Row
That works perfectly, thank you for your help brucevde!
O, and side question. I'm not a native VB coder, my forte's are Java and C derivatives. I have seen the "With Me.flexGrid...End With" code structures in other examples, and see that it can be used for short hand. Are there advantages to using that structure, either for speed or compilation or anything?
Last edited by DSimmon; Apr 20th, 2007 at 08:35 AM.
Currently debugging and building: VB6 SP6
-
Apr 20th, 2007, 10:12 AM
#6
Re: MSHFlexGrid - Set Selected Row
Basically, accessing an object requires some processing. Using With eliminates the need to access the object on each statement, the object only needs to be accessed once. So there is a speed advantage using With, especially if you are accessing multiple properties that are several layers deep. ie
Form1.Text1.Text
Form1.Text1.BackColor
Plus the code is easier to read.
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
|