System Programming
--
Questions
--
Followers
Top Experts
How Set FOCUS on any ITEM in MFC, CListCtrl
About working with MFC, CListCtrl .
From answers I understood how Select/Deselect Item. But I need to set Focus on Selected Item.
If I immitate rounding, I mean: selection on Top Item and User press Up Key. It should Select most down Item and focus on it and scroll if necessary. But after using
m_List.SetItemState(Item,
LVIS_FOCUSED, LVIS_FOCUSED);
(Of course, ITEM = SIZE - 1)
It ALWAYS focus on (ITEM - 1) - next up item
Please advise.
Forgot to ask: How to set selection without user clicking? Because no selection at all until user clicked.
Ilya
From answers I understood how Select/Deselect Item. But I need to set Focus on Selected Item.
If I immitate rounding, I mean: selection on Top Item and User press Up Key. It should Select most down Item and focus on it and scroll if necessary. But after using
m_List.SetItemState(Item,
LVIS_FOCUSED, LVIS_FOCUSED);
(Of course, ITEM = SIZE - 1)
It ALWAYS focus on (ITEM - 1) - next up item
Please advise.
Forgot to ask: How to set selection without user clicking? Because no selection at all until user clicked.
Ilya
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
You may try with LVIS_FOCUSED
Try this :
SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
-MAHESH
Try this :
SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
-MAHESH
>>How to set selection without user clicking
To select an item you may use:
m_ListCtrl.SetItemState(nI tem, LVIS_SELECTED, LVIS_SELECTED);
To unselect an item you must use:
m_ListCtrl.SetItemState(nI tem, 0, LVIS_SELECTED);
Try to use LVIS_SELECTED | LVIS_FOCUSED for selection focus
SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
-MAHESH
To select an item you may use:
m_ListCtrl.SetItemState(nI
To unselect an item you must use:
m_ListCtrl.SetItemState(nI
Try to use LVIS_SELECTED | LVIS_FOCUSED for selection focus
SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
-MAHESH
You talk about focus and selection and mix the two in the question - you do understand that they are two different things I hope. (Focus is NOT the same as selection).
>> m_List.SetItemState(Item, LVIS_FOCUSED, LVIS_FOCUSED);
>> (Of course, ITEM = SIZE - 1)It ALWAYS focus on (ITEM - 1) - next up item
Have you already allowed for the zero based counting when you calculate SIZE ? That would give the behaviour you describe.
To 'scroll' to an item you need the EnsureVisible function - m_List.EnsureVisible(item, FALSE);
>> m_List.SetItemState(Item, LVIS_FOCUSED, LVIS_FOCUSED);
>> (Of course, ITEM = SIZE - 1)It ALWAYS focus on (ITEM - 1) - next up item
Have you already allowed for the zero based counting when you calculate SIZE ? That would give the behaviour you describe.
To 'scroll' to an item you need the EnsureVisible function - m_List.EnsureVisible(item,






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Thank you all very much!
To get what I need all three lines are necessary:
m_List.SetItemState(Item, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
m_List.EnsureVisible(Item, FALSE);
m_List.SetFocus();
To get what I need all three lines are necessary:
m_List.SetItemState(Item, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
m_List.EnsureVisible(Item,
m_List.SetFocus();
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
>>Thank you all very much!
>>To get what I need all three lines are necessary:
ilyayudkevich,
Are you sure you have accepted right solution ? That should not be split as I have also helped you for getting correct solution ???
-MAHESH
>>To get what I need all three lines are necessary:
ilyayudkevich,
Are you sure you have accepted right solution ? That should not be split as I have also helped you for getting correct solution ???
-MAHESH
System Programming
--
Questions
--
Followers
Top Experts
Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.