dcsimg
Results 1 to 4 of 4

Thread: Highlight DataGrid Row and use Mouse Scroll Wheel on DataGrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    239

    Wink Highlight DataGrid Row and use Mouse Scroll Wheel on DataGrid

    How to Highlight a DataGrid Row and Use Mouse Wheel to Scroll in a DataGrid

    There are two features demonstrated in this program.

    NB! Please follow these directions in order to see the correct results.

    First is how to programmatically highlight a row in a DataGrid.

    1. To have the appropriate DataGrid Row become highlighted, simply
    input a last name (use Martin) in the first TextBox and click the
    “Highlight Grid” Command Button. You will obtain the desired result.

    2. Next Click the Clear Command button then select the
    “Find and Highlight Selected Grid Item” Command Button,
    and input a last name in the Input Dialog Box (type in Jones)

    The next feature is using the Mouse Scroll Wheel to navigate the DataGrid itself..

    3. When the program starts there is red right arrow in the upper left
    corner of the DataGrid. In order to use the Mouse Scroll Button the
    DataGrid must have the focus, to do this click on this Red Arrow.
    This action will highlight the first row of the Grid and now you can
    Use the Mouse Scroll Wheel to navigate the Grid.

    John P. Cunningham
    3/22/2010
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    Re: Highlight DataGrid Row and use Mouse Scroll Wheel on DataGrid

    Hi John

    A little out of date I know, but just in case you are still about.

    I have a legacy program, in VB6, that now utilises your Mouse Scroll Functionality(Thank You, implemented not long after this original post) and had some recent feedback.

    When you click/highlight a cell, you immediately lose mouse scroll ability; the only way to get it back is to Click in the Row or Column header.

    Is this something that you have encountered? and if so I would ask your advice on a fix; as I have basically copied your functions and have struggled with attempts to work this out.

    Thanks in advance if this finds you.
    FLOG

  3. #3
    New Member
    Join Date
    Mar 2015
    Posts
    1

    Re: Highlight DataGrid Row and use Mouse Scroll Wheel on DataGrid

    Hi FLOG

    This may be useful to you and others having a similar issue or looking to optimize the working of jonhpc's solution for scrolling the Datagrid:

    - If you set the MakeeStyle to 2-Highlight or NoMarquee, the DBGrid will always scroll as long as it has the focus. (more details here http://www.experts-exchange.com/Prog..._24059857.html )

    This is because, by default the DBGrid's "Marquee style" is set to "Floating Editor" which creates an invisible textbox (with blinking cursor) that garbs the focus taking it away from the Datagrid itself. By doing this, it's the textbox (and not the grid) that starts capturing the WM_WHEELSCROLL messages causing the grid not scroll.
    That's why you need to click the arrow as described (to select the entire row) to return the focus to the grid itself and make the mousewheel scroll/john's trick work.

    To work around this, set the MarqueeStyle to something other than "Floating Editor", thus keeping the focus on the grid, and making the Mousewheel function work more consistently; if you don't need to edit the data on the grid itself, this is an ideal solution.
    (there are still Markee options that select the cell, keeping focus on the grid by default but will still give you the text editor on a double click or "enter", giving you the best of both worlds)

    A word of caution: johnpc's code doesn't seem to be returning the WndProc to it's original value when the form unloads; this can cause erratic behaviours and is not a best practice.
    In addition to john's (excellent)code, you should add the following line to your Form_Unload event:
    SetWindowLong(DataGrid1.hWnd, GWL_WNDPROC, lpPrevWndProc )
    This will restore the original WndProc so that when parts of the software start getting unloaded by VB, you can rest assured the grid is being taken care of by a WndProc, in this case its original/default WndProc.

    All the best
    Pedro.

  4. #4
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    Re: Highlight DataGrid Row and use Mouse Scroll Wheel on DataGrid

    Thanks & Great job pramilo, you gotta love coding; can search for ever for something so simple.

    I have tested at my end and works perfectly; and had already taken care of the Unhook methods in original build.

    Thanks again.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width