-
February 23rd, 2004, 08:32 PM
#1
CListCtrl
Dear all
I create a dialog and add a List control which is a icon list control.
i can selete several items if i press Ctrl or Shift.
now, i want several items being seleted and set focus when a user open this dialog.
this means if Item 1,2,3 is seleted, then user close dialog. next time when user open the dialog, the Item1,2,3 is seleted and set focus.
**I just want to know how to set several items' focus, when a user open dialog.
-
February 23rd, 2004, 10:42 PM
#2
You should be able to use CListCtrl::SetItemState to set mutiple items as selected (you would have to call it once for each item you want to select). As for focus, only one item can have the focus, but you can use CListCtrl::SetItemState to do that as well.
-
February 24th, 2004, 12:07 AM
#3
Hi there
I used SetItemState, but only the last item will be seleted and get focus;
Here is my code
for(int i=0;i<=10;i++)
{
m_ImageList.SetItemState(i,LVIS_SELECTED,LVIS_SELECTED);
}
Thanks
-
February 24th, 2004, 12:34 AM
#4
Make sure your listctrl is set to "Always Show Selection", and it should work.
-
February 24th, 2004, 12:46 AM
#5
Here is quick example I tried:
Dialog app with CListCtrl (with Always Show Selection = TRUE, and View set to list). CListCtrl member variable added (m_List)
In initdialog under the todo comments I added following:
Code:
// TODO: Add extra initialization here
m_List.SetFocus();
CString sLabel;
// add 10 items to list
for(int i = 0;i < 9; i++)
{
sLabel.Format("Item%d", i);
m_List.InsertItem(i, sLabel);
}
// select 1st 5 items
for(int i = 0;i < 5; i++)
m_List.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED );
// set focus to first item
m_List.SetItemState(0, LVIS_FOCUSED , LVIS_FOCUSED );
// return false because I set focus to a control
return false; // return TRUE unless you set the focus to a control
When running the program the 1st 5 items are selected and the 1st item has focus, so it should work for you.
Last edited by RussG1; February 24th, 2004 at 12:49 AM.
-
February 24th, 2004, 01:08 AM
#6
Thank you for your help, i am going to try it now.
-
February 24th, 2004, 02:12 AM
#7
Originally posted by wow9999
I used SetItemState, but only the last item will be seleted and get focus;
You should also make sure that your list control doesn't have the LVS_SINGLESEL style set.
-
February 24th, 2004, 03:29 PM
#8
The third Parameter of SetItemState is a mask value and LVIS_SELECTED is not a mask value.
-
February 24th, 2004, 06:41 PM
#9
Originally posted by Sam Hobbs
The third Parameter of SetItemState is a mask value and LVIS_SELECTED is not a mask value.
The mask parameter for SetItemState is a stateMask and LVIS_SELECTED can be used for this parameter to tell SetItemState that you want only the items selection bits to be changed, so you can use LVIS_SELECTED as a mask value in this case.
Russ
-
February 24th, 2004, 07:37 PM
#10
This actually is documented.
From MSDN:
nState
New values for the state bits.
nMask
Mask specifying which state bits to change.
You need a mask to be able to "drop" a particular state, like in:
Code:
m_List.SetItemState(item, 0, LVIS_SELECTED);
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 24th, 2004, 07:45 PM
#11
Yes, I agree the docs are a bit lacking here, but it does say the mask value for SetItemState specifies which state bits to change. LVIS_SELECTED is a state bit, whereas LVIF_IMAGE is not. If you dig a little deeper and look at the version that takes a LVITEM structure as a parameter, and lookup the LVITEM structure itself, you will find one of the parameters is stateMask, and the decription of that is as follow:
Value specifying which bits of the state member will be retrieved or modified. For example, setting this member to LVIS_SELECTED will cause only the item's selection state to be retrieved.
This member allows you to modify one or more item states without having to retrieve all of the item states first. For example, setting this member to LVIS_SELECTED and state to zero will cause the item's selection state to be cleared, but none of the other states will be affected.
From this I am making a small leap in thinking that the same thing goes for the mask value of SetItemState since it says the mask value only specifies which state bits to change (as does the decription of stateMask), and that the docs should probably say stateMask rather than mask for that parameter, to be more clear (a list of valid mask value's would be nice too).
If you wanna to be completely safe then just do it using an LVITEM structure instead, but personally I think that this is what is meant for the mask value for SetItemState, otherwise you really have nothing to use for the mask value in SetItemState, and the function is almost useless.
Russ
-
February 24th, 2004, 07:48 PM
#12
Originally posted by RussG1
The mask parameter for SetItemState is a stateMask and LVIS_SELECTED can be used for this parameter to tell SetItemState that you want only the items selection bits to be changed, so you can use LVIS_SELECTED as a mask value in this case.
Russ
Yes.
I am sorry that I was confused.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|