winapi - How to set focus on a List View item? -


i trying write program selects , focuses specific item in list view.

why calling listview_setselectionmark (or sending lvm_setselectionmark) not working set focus on list view item? after calling listview_setselectionmark, focus remains rather changing new location; when press arrow key moves focused item rather item specified.

here snippet of code selects , focuses item:

listview_setitemstate(this->m_hwndchild, index, lvni_selected, lvni_selected); listview_setselectionmark(this->m_hwndchild, index); listview_ensurevisible(this->m_hwndchild, index, false); setfocus(this->m_hwndchild); 

here full gist. each time press ctrl-r, selects random item of list view.

the selectionmark has nothing focus. merely indicates item starts multiple selection.

you need use lvis_focused item state instead:

listview_setitemstate(this->m_hwndchild, index, lvni_selected | lvni_focused, lvni_selected | lvni_focused); listview_ensurevisible(this->m_hwndchild, index, false); setfocus(this->m_hwndchild); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -