CListCtrl, Why doesn't this work?
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
Re: CListCtrl, Why doesn't this work?
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.
Re: CListCtrl, Why doesn't this work?
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
Re: CListCtrl, Why doesn't this work?
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.
Re: CListCtrl, Why doesn't this work?
why did it lose focus???
Sally
Re: CListCtrl, Why doesn't this work?
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
Re: CListCtrl, Why doesn't this work?
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