Click to See Complete Forum and Search --> : CListCtrl, Why doesn't this work?
Jaime Wyant
May 10th, 1999, 09:54 AM
I am trying to select all the items in a list control, but the below code doesn't seem to work... Can anyone tell me what I am missing?
int num_items = m_List.GetItemCount();
for (int i = 0; i < num_items; i++)
m_List.SetItem(i, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, LVIS_SELECTED, 0);
Thanks,
Jaime
BrianOG
May 10th, 1999, 10:32 AM
Is only the last one being selected? If so, you dont have multiple select turned on.
You could also tryfor ( int i=0; i<m_list.GetItemCount(); i++ )
m_list.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
This works for me.
Jaime Wyant
May 10th, 1999, 11:22 AM
I figured out what it was...
When the "Select All" button was pressed, my code executed and did what it was supposed to do, but the results did not show up because the ListCtrl lost focus...
SO, i just did list.SetFocus() and all is well now!
Thanks,
Jaime
BrianOG
May 11th, 1999, 02:01 AM
A nice trick here is to turn on "Show Selection Always" (in the resource editor - append the style in the Create call). Then even when th list control does no have the focus, the items will show up selected.
sally
May 11th, 1999, 02:23 AM
why did it lose focus???
Sally
Sally
May 11th, 1999, 02:23 AM
why did it lose focus???
Sally
Daren Chandisingh
May 11th, 1999, 04:09 AM
The list control lost focus because a button was clicked ("Select All" in this case). When this happens the button gains the input focus; hence the list control loses it.
--
Daren Chandisingh
sally
May 11th, 1999, 05:44 AM
but if you click on another control, with that comes the idea that you have transferred control to that control, in this case the button, I beleive that the best user interface response is to keep the focus as it is and to use SHOW ALWAYS.
Sally
Sally
May 11th, 1999, 05:44 AM
but if you click on another control, with that comes the idea that you have transferred control to that control, in this case the button, I beleive that the best user interface response is to keep the focus as it is and to use SHOW ALWAYS.
Sally
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.