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

  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
    291
    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, 12:05 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM