Win32 (C/C++) Getting selected ListView item...

This is a discussion on Win32 (C/C++) Getting selected ListView item... within the Windows Programming forums, part of the Platform Specific Boards category; This is driving me crazy. Is there a way to find out which item is selected in a list view. ...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up Win32 (C/C++) Getting selected ListView item...

    This is driving me crazy. Is there a way to find out which item is selected in a list view. I've tried heaps of things but I can't seem to get anything to work. This is how I've declared it:

    Code:
    hList = CreateWindow( WC_LISTVIEW, "", WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | LVS_SINGLESEL, 0, 20, 215, 200, hWindow, (HMENU)0, GetInstance(), NULL );
    As you can see, I only want one selected at a time and I want a UINT to tell me which one it is.

    Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    What's the problem with LVIS_SELECTED state ?

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Have you tryed with LVM_GETNEXTITEM? The next code works for me:

    Code:
    int i=SendMessage(hList,LVM_GETNEXTITEM,(WPARAM)-1,(LPARAM)LVNI_SELECTED);
    The WPARAM=-1 means to reach from the first item of the list; and the LPARAM means how has to be the item's state, in that case you want it selected so set it to LVNI_SELECTED; also you may want to try that is also focused, so you can try LVNI_SELECTED|LVNI_FOCUSED.

    Hope that helps
    Niara

  4. #4
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Yes, the LVM_GETNEXTITEM worked for me, though I used LVNI_FOCUSED as the last parameter... still works though, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  3. Replies: 6
    Last Post: 07-10-2006, 01:05 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21