CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    23

    Help with MSFlexgrid!

    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.


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Help with MSFlexgrid!

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Help with MSFlexgrid!

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Help with MSFlexgrid!

    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
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured