Thread: Can't find 2 messages for a list view coontrol

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Can't find 2 messages for a list view coontrol

    Hi, I can't find the 2 messages for list view controls to check which item is selected, and to select a certain item. These messages are LB_GETCURSEL, and LB_SETCURSEL for a list box control.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Also how do you make it that so when you click on an item the whole line is selected, including the subitems?

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    common, somebody has got to know how to do this.

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    The list view has functions rather than messages to determine and set the current selection. ListView_GetSelectionMark() will return the index of the current item if found, or -1 in the absense of a selection.

    Use ListView_SetExtendedListViewStyle() with the LVS_EX_FULLROWSELECT flag to force full row selections.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Thanks for the help. The full row selection works, aswell as the ListView_GetSelectionMark() function. However I still can't get the program to select a line. I tried ListView_SetSelectionMark() and it returns the old selection mark, but it won't set the new one. Also after i've called the function once and then call it again, it returns the item that i set the first time I called it. It doesn't select it though. Is there something else I have to do?

  6. #6
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Actually, ListView_SetSelectionMark() is working as it should. This is because it's defining the selection mark (the point at which multiple selection would start), not explicitly selecting any items. To get proper selection, set the mark as you've done and also change the item's state to selected using ListView_SetItemState() and LVIS_SELECTED.

    ListView_GetSelectionMark() will return the index of the first item selected, and the control makes it your job to check all the items' states to see if the user has selected multiple objects if it's vital to your program's operation.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Hmmm. I still can't get it to work. My code is below.

    ListView_SetSelectionMark(GetDlgItem(hwnd, IDC_MUSICLIST), searchResult);
    ListView_SetItemState(GetDlgItem(hwnd, IDC_MUSICLIST), searchResult, LVIS_FOCUSED | LVIS_SELECTED, NULL);

    Also I only need to have one item selected at a time.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    never mind, i found the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. list view doesn't receive LBN_SELCHANGE messages
    By eth0 in forum Windows Programming
    Replies: 6
    Last Post: 01-17-2006, 06:54 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM