multiple selections in List View (LVS)
-
Hello! This is my first post on the Code Project, maybe you can help me. In my dialog box I have a list view and a check box. If the check box is unselected, the user should be able to select any list item they wish. However, if the check box is selected, and there are only two list items, I want both list items automatically selected as it is a requirement of my application (right now, the user has to Shift select both list items before proceeding, and I want to remove this ambiguity by having both required list items selected for them). However if there are more than two items in the list, there should be no automatic highlighting. That said, I'm not sure how to go about this in Visual C++ .NET. Any suggestions? Thank you. :)
-
Hello! This is my first post on the Code Project, maybe you can help me. In my dialog box I have a list view and a check box. If the check box is unselected, the user should be able to select any list item they wish. However, if the check box is selected, and there are only two list items, I want both list items automatically selected as it is a requirement of my application (right now, the user has to Shift select both list items before proceeding, and I want to remove this ambiguity by having both required list items selected for them). However if there are more than two items in the list, there should be no automatic highlighting. That said, I'm not sure how to go about this in Visual C++ .NET. Any suggestions? Thank you. :)
See the FAQ: 4.10 How do I programmatically select an item in a list view control?[^]
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer
-
See the FAQ: 4.10 How do I programmatically select an item in a list view control?[^]
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer
Mike, where the FAQ says: Here is how to select an item whose index is nItemToSelect:
// MFC: wndYourList.SetItemState ( nItemToSelect, LVIS_SELECTED, LVIS_SELECTED );
does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"? any others have alternative suggestions? (sorry, I am a novice) -
Mike, where the FAQ says: Here is how to select an item whose index is nItemToSelect:
// MFC: wndYourList.SetItemState ( nItemToSelect, LVIS_SELECTED, LVIS_SELECTED );
does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"? any others have alternative suggestions? (sorry, I am a novice)aafcls wrote:
does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"?
Index refers to the item number, but it isn't necessarily in order (if you allow sorting your list items, it will be highly random). You should just need to call CListCtrl::GetItemCount to see how many items there are in the list and if there are 2 or fewer, use CListCtrl::GetNextItem with the default flags to get the item index. After that, use the index in your CListCtrl::SetItemState call. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Mike, where the FAQ says: Here is how to select an item whose index is nItemToSelect:
// MFC: wndYourList.SetItemState ( nItemToSelect, LVIS_SELECTED, LVIS_SELECTED );
does "index" refer to an actual number? for example, if I have 2 items in my list, would the first item be index "0", then index "1"? any others have alternative suggestions? (sorry, I am a novice)Yes, item numbering starts at 0
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer
-
Yes, item numbering starts at 0
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer
-
Thanks, this works. However, instead of selecting each item by index number, is there a way to "select all"? (instead of having to do individual
SetItemState
)Pass -1 for the item index to set the state of all items at once.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer