Menu

Custom ListView control

Help
Robert
2024-06-03
2024-06-11
  • Robert

    Robert - 2024-06-03

    Hi,

    I'm coding some type of shift/duty calendar. For this I need a ListView which has a fixed first column for all the names of the co-workers. I tried to follow your custom control sample and this CodeProject tutorial. All google searchs just end with the suggestion to use some type of data grid, but all native ones are just C# stuff. But I guess I missed somthing.

    Best regards from Germany,
    Robert

     

    Last edit: Robert 2024-06-03
  • David

    David - 2024-06-04

    Hi Robert,

    A list-view control has an internal header control. This is used to resize columns when the list-view uses the LVS_REPORT window style.

    When the user drags a divider in the header control, the header control sends a HDN_TRACK notification to its parent window, which in this case is the ListView control. When this notification is handled, we can return FALSE to continue tracking the divider, or TRUE to end tracking.

    The HDN_TRACK notification has a pointer to an NMHEADER structure that contains information about the header control and the item whose divider is being dragged. We can use that to determine if the first divider is being dragged.

    In theory at least, a standard list-view control seems quite capable of doing what you want.

    Having said that, list-view controls are quite limited and you might want to consider a custom grid control. Here are two controls I found on CodeProject. The first grid control uses the Windows API directly, and should be easy to integrate with Win32++.

    The second control is probably more advanced but it uses MFC. This might make it difficult to port to Win32++.

    https://www.codeproject.com/Articles/681771/Simple-Grid-A-Win-message-based-grid-control

    https://www.codeproject.com/Articles/8/MFC-Grid-control-2-27

    Best regards,
    David

     
  • Robert

    Robert - 2024-06-04

    Hi David,

    thanks for your help. I think I'll try the Simple Grid then. I just took a quick look, but I guess giving the grid a handle of a CDocker as a parent will work.

    Best regards from Germany,
    Robert

     
  • Robert

    Robert - 2024-06-09

    Hi David,

    I tried your suggestions. The first one doesn't work well for me. The second one is what I need but way to complex and complicated. I absolutely don't know any MFC, so I'm not able to port it to Win32++.
    I also found this one: https://www.codeproject.com/Articles/38168/Win32-SDK-Data-Grid-View-Made-Easy. This seems small and portable. But doesn't fulfill my needs completely.

    Maybe you can help me without crawling down the porting rabbit hole. My list/data grid just has a few points to fulfill:
    * Fixing the first coloumn/row header. Meening prevent it from horizontal scrolling.
    * Multiple cell selection. (continuous cells in rows, continuous cell in coloumns, and individual cells)
    * Data represented by cell ids is processed/changed in my code and then send to the grid again. (Therefore updating individual cells would be nice.)
    * No need for an editor. Just showing my data and getting selected cell ids when a button or hotkey is clicked.

    Maybe all of this is possible with a custom extended listview. I guess the hardest/impossible one is the selection problem with a list view.

    Best regards from Germany,
    Robert.

     

    Last edit: Robert 2024-06-10
  • David

    David - 2024-06-11

    Hi Robert,

    Yes I would be happy to help you with the code. You can contact me directly via the email address listed in the copyright section of the code.

    In regard to the requirements you mentioned:

    • Fixing the width of the first column should be made possible handling list-view HDN_TRACK notifications.

    • Selecting multiple individual cells isn't supported by the list view control. It should be possible to simulate that by developing code that stores the "selected" cells and renders them with a different colour using owner-draw.

    • Allowing cell information to be changed and dynamically updated is supported by be the list-view control using the LVN_GETDISPINFO notification.

    Best regards,
    David

     

Log in to post a comment.