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.
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.
Also how do you make it that so when you click on an item the whole line is selected, including the subitems?
common, somebody has got to know how to do this.
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
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?
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
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.
never mind, i found the problem