Click to See Complete Forum and Search --> : Help with MSFlexgrid!


Simon Phillips
October 24th, 2001, 09:29 AM
PLEASE HELP ! I have an MSFlexgrid in a project that fills up with hundreds of items. I have written a search function that searches through the grid for a specific item. When my function finds the item I higlight the particular row using 'Col' and 'ColSel' properties. However, if the selected row is way down the list (ie : After the first on screen page) then I have to manually scroll through the list to find the selected row. I would like to automatically scroll the grid so it jumps to the portion with the highlighted row but can't seem to figure out how to do it !!! Any ideas most appreciated! Cheers. Simon.

Iouri
October 24th, 2001, 09:40 AM
Here is API to scroll msfg

WM_VSCROLL message to an MSFlexGrid control it moves the scrollbar and contents.

private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Long) as Long


private Const WM_VSCROLL = &h115

'to scroll a grid upwards, wParam is 0
public Sub ScrollGridUp(byval fg as MSFlexGrid)

Dim lRet as Long

lRet = SendMessage(fg.hwnd, WM_VSCROLL,0,0)

End Sub


'to scroll a grid down, wParam is 1
public Sub ScrollGridDown(byval fg as MSFlexGrid)

Dim lRet as Long

lRet = SendMessage(fg.hwnd, WM_VSCROLL,1,0)

End Sub


Iouri Boutchkine
iouri@hotsheet.com

Iouri
October 24th, 2001, 09:42 AM
Here is how you can scroll page up and down and go to the top/bottom

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'Constant
Const WM_VSCROLL = &H115
Const SB_BOTTOM = 7
Const SB_TOP = 6
Const SB_PAGEDOWN = 3
Const SB_PAGEUP = 2

Private Sub Command2_Click()
SendMessage MSFG.hwnd, WM_VSCROLL, SB_BOTTOM, 0
'MSFG is my FlexGrid control, can be cha
' nged to ListBox

End Sub

Private Sub Command3_Click()
SendMessage MSFG.hwnd, WM_VSCROLL, SB_TOP, 0

End Sub

Private Sub Command4_Click()
SendMessage MSFG.hwnd, WM_VSCROLL, SB_PAGEDOWN, 0

End Sub

Private Sub Command5_Click()
SendMessage MSFG.hwnd, WM_VSCROLL, SB_PAGEUP, 0

End Sub


Iouri Boutchkine
iouri@hotsheet.com

Iouri
October 24th, 2001, 09:44 AM
Also you can go to the selected row using TopRow property


That is a property of MSFG.
Set it to desired row value, and it will become top row. So, if you want that particular record will be in the
middle of control, you can set TopRow to value, say, 10 less than desired row (of course, desired row must
have at least 10 rows above it.

'example

Private Sub MSFlexGrid1_Scroll()
Label1.Caption = MSFlexGrid1.TopRow & " / " & MSFlexGrid1.Row & " / " & MSFlexGrid1.Rows
End Sub




Iouri Boutchkine
iouri@hotsheet.com