listview assistance
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: listview assistance

  1. #1
    Join Date
    Nov 2014
    Posts
    30

    listview assistance

    I am trying to get the current selection of a listview in report mode when the selection is created with the up and down arrow keys.
    I am able to get the selection fine with a mouse click but can't figure out how to do it when the selection is changed using the keyboard
    ZPRINT is a debuging utility I use:
    https://www.codeproject.com/Articles...e-for-bit-only
    ---------------------------------------------------
    str is library code returning the string representation of a number
    ------------------------------------------------------------------------------
    I am only testing so using only the up and down arrow keys so no code to determine
    the actual key is presented.
    James

    Code:
       if(Msg == WM_NOTIFY )
        {
            if(LOWORD(wParam) == IDC_LSV1 )
            {
                hListView = GetDlgItem( hWnd, IDC_LSV1);
                lpnmhdr = ( LPNMHDR) lParam;
                if(lpnmhdr->code == NM_CLICK )
                {
                    iSelect = ListView_GetNextItem( hListView, - 1, LVNI_FOCUSED);
                    strcpy(stemp, str(iSelect));
                    ZPRINT(stemp);
                }
                else if(lpnmhdr->code == LVN_KEYDOWN )
                {
                    iSelect = ListView_GetNextItem( hListView, - 1, LVNI_SELECTED);
                    strcpy(stemp, str(iSelect));
                    ZPRINT(stemp);
                }
            }
        }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,955

    Re: listview assistance

    Did you try to handle the LVN_ITEMCHANGED notification?
    Or you only need to process the selections made by keyboard?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2014
    Posts
    30

    Re: listview assistance

    Thank you VictorN.
    This works for both clicks and key up/dn.
    James

    Code:
                hListView = GetDlgItem( hWnd, IDC_LSV1);
                lpnmhdr = ( LPNMHDR) lParam;
                if(lpnmhdr->code == LVN_ITEMCHANGED )
                {
                    iSelect = ListView_GetNextItem( hListView, - 1, LVNI_FOCUSED | LVNI_SELECTED);
                    if(iSelect > -1 )
                    {
                        strcpy(stemp, str(iSelect));
                        ZPRINT(stemp);
                    }
                }
            }

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)