Hi,
In the list view control, if you delete an item how do set back the focus onto any other item in the list.
thanx
giri
Printable View
Hi,
In the list view control, if you delete an item how do set back the focus onto any other item in the list.
thanx
giri
The code is simple, but you must handle 2 cases:
* the deleted item being the first in the list - you then select the next one.
* the deleted item is somewehere else - selecting the previous item is probably best.
For the code fragment, assume m_nSelectedItem was the index of the deleted item.
...
if(m_nSelectedItem == 0)
{
// Select the next item in the list
LVITEM lvItem;
lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
m_ListCtrl.SetFocus();
m_ListCtrl.SetItemState(m_nSelectedItem, &lvItem);
}
else
{
// Select the previous item in the list
LVITEM lvItem;
lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
m_ListCtrl.SetFocus();
m_ListCtrl.SetItemState(m_nSelectedItem - 1, &lvItem);
}
NB: _you_ may not need to use SetFocus()
Stu
I have a search function in my application which is looking from the CListCtrl. I have done the SetItemState and managed to highlight and focus on the item.
My problem is how can I make the CListCtrl to scroll to the focused item's page? Thanks.
This surprises me - I assume you don't have access to VC help or even the entire MSDN library at http://msdn.microsoft.com/library/default.htm ?! ;-)
Try CListCtrl::EnsureVisible()