Thread: Can a listbox row be editable by the user? like a spreadsheet?

  1. #16
    Registered User
    Join Date
    Jun 2008
    Ok, more issues today...

    1. Is there an easy way to determine the max number of items a ListView can hold without auto-creating a vertical scrollbar and/or disable said scrollbar? If I get into resizing the control on window resize, I want to be able to determine the number of items to set for the ListView to be filled on screen without any scrolling going on in the box. Naturally, the only message I can find that's close is LVM_APPROXIMATEVIEWRECT and it does the exact opposite of what I need. I need to calculate how many items can be held based on with/height, not with/height needed to hold X number of items. I'm working on my own function to do it based off the rect of the ListView and first item in it.

    Actually, found part of what I needed to know for disabling the scrollbar.
    Quote Originally Posted by MSDN
    Scrolling is disabled. All items must be within the client area. This style is not compatible with the LVS_LIST or LVS_REPORT styles. See Knowledge Base Article Q137520 for further discussion.
    There's a workaround in that knowledge base article but it doesn't tell you the exact messages/notifications to call the function from.

    2. Which notification/message do you use to catch mouse wheel up/down scrolling?
    Last edited by Viper187; 06-06-2008 at 08:37 PM.

  2. #17
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    >> but it doesn't tell you the exact messages/notifications to call the function from.
    It said to call it - PositionHeader - "whenever the ListView is created, resized, the view is changed, or the parent window receives the WM_SYSPARAMETERCHANGE message."

    As for determining the number of rows that will fit - my first attempt would be something like: "(LV.ClientRect.Height - LV.Header.ClientRect.Height) / LV.ItemRect.Height"
    LV.ClientRect comes from "GetClientRect(hwndLV)"
    LV.Header.ClientRect comes from "GetClientRect(LVM_GETHEADER())"
    LV.ItemRect comes from "LVM_GETITEMRECT()"

    >> mouse wheel


  3. #18
    Registered User
    Join Date
    Jun 2008

    "created, resized, the view is changed" - but which messages/notifications would be for resizing and "changing the view"? The damn comment could've said that.

    Now I have 1 small issue with my function to get the item rect and compare to the ListView rect. The item height isn't retrieved when the listview is empty. I thought about substituting the header item height, but it's not the same. Only thing I can think is maybe to check if an items exists, and if not, add a blank one so I get the right height. The function to fill the box clears it each time anyway, so I guess it can't hurt.

    Well, this took a while, but it works.

    int CalcPageSize(HWND hListView){
        RECT ItemRect; memset(&ItemRect,0,sizeof(ItemRect));
        int iCount = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0);
        if (!(iCount)) {
            LVITEM LvItem; memset(&LvItem,0,sizeof(LvItem));
            SendMessage(hListView, LVM_INSERTITEM, 0, (LPARAM)&LvItem);
        ItemRect.left = LVIR_LABEL;
        SendMessage(hListView, LVM_GETITEMRECT, 0, (LPARAM)&ItemRect);
        HWND hHeader = (HWND)SendMessage(hListView, LVM_GETHEADER, 0, 0);
        RECT HeaderRect; memset(&HeaderRect,0,sizeof(HeaderRect));
        if (hHeader) {
            HeaderRect.left = LVIR_LABEL;
            GetWindowRect(hHeader, &HeaderRect);
        if ( (ItemRect.bottom - <= 0 ) {
            if ( (HeaderRect.bottom - > 0 ) { 
                ItemRect.bottom = HeaderRect.bottom;
            } else { return DEFAULT_PAGE_SIZE; }
        RECT lvRect; memset(&lvRect,0,sizeof(lvRect));
        if (GetWindowRect(hListView, &lvRect) == 0 ) { return DEFAULT_PAGE_SIZE; }
        return (((lvRect.bottom - - (HeaderRect.bottom - / (ItemRect.bottom -;
    Last edited by Viper187; 06-06-2008 at 10:36 PM.

  4. #19
    Registered User
    Join Date
    Jun 2008
    Dammit! I still can't figure out exactly how to handle the WM_MOUSEWHEEL notification, and I can't find any example code. Anyone got any? Preferably without MFC.

    edit: Great. I can capture the event, but not when the ListView is active. How do I check if ListView has focus and override the default handler?

    edit: Ok, overriding the handler worked. Now if I just need to figure out how to use the value from the wheel.

    Took me forever to find RealChildWindowFromPoint(). I wish there was a better reference for straight C/API programming than MSDN.
    Last edited by Viper187; 06-07-2008 at 08:15 AM.

  5. #20
    Registered User
    Join Date
    Jun 2008
    Other stuff is pretty much sorted out, but now I have an issue with handling LVN_KEYDOWN. I can't seem to figure out how to check if CTRL and DOWN are being pressed at the same time. I tried LVN_KEYDOWN / WM_KEYDOWN and tried checking for CTRL being held with GetKeyState, but it's not giving me anything. Edit: ......... I was checking something else before getting to that. Long story short, I wasn't testing the right condition.
    Last edited by Viper187; 06-07-2008 at 06:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 08:52 PM
  2. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 06:01 AM
  3. comparing user input
    By lambs4 in forum C Programming
    Replies: 5
    Last Post: 12-15-2002, 10:28 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 08:28 AM