SetFocus problem
-
I have an SDI application, with a splitter window that have in left view an CTreeView and right side an CListView.In each one I have some items. I override PreTranslateMessage in each one to be able on tab key to move focus from tree to view and viceversa :
BOOL CMyTree::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base classif(pMsg->message == WM\_KEYDOWN && pMsg->wParam == VK\_TAB) { CMyListView\* pView = (CMyListView\*)pChild->GetMyListView(); pView->SetFocus(); pView->GetListCtrl().SetItemState(0, LVIS\_SELECTED | LVIS\_FOCUSED, LVIS\_SELECTED | LVIS\_FOCUSED); } return TRUE; } return CTreeView::PreTranslateMessage(pMsg);
}
I see that the focus has moved. Somewhere in menu I have a delete menu that could delete items from tree or from listview. Let's say that I'm in treeview. I press tab and I see that the focus has moved on listview. When I try to delete an item I see that I delete an item from treeview not from list view .... so, from some reason, the focus remained in treeview ... The the deletion goes well only when I move the focus from tree on list view by click with mouse in list view ... My question is, is enough to call SetFocus(); to move an focus from tree view to listview ?
-
I have an SDI application, with a splitter window that have in left view an CTreeView and right side an CListView.In each one I have some items. I override PreTranslateMessage in each one to be able on tab key to move focus from tree to view and viceversa :
BOOL CMyTree::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base classif(pMsg->message == WM\_KEYDOWN && pMsg->wParam == VK\_TAB) { CMyListView\* pView = (CMyListView\*)pChild->GetMyListView(); pView->SetFocus(); pView->GetListCtrl().SetItemState(0, LVIS\_SELECTED | LVIS\_FOCUSED, LVIS\_SELECTED | LVIS\_FOCUSED); } return TRUE; } return CTreeView::PreTranslateMessage(pMsg);
}
I see that the focus has moved. Somewhere in menu I have a delete menu that could delete items from tree or from listview. Let's say that I'm in treeview. I press tab and I see that the focus has moved on listview. When I try to delete an item I see that I delete an item from treeview not from list view .... so, from some reason, the focus remained in treeview ... The the deletion goes well only when I move the focus from tree on list view by click with mouse in list view ... My question is, is enough to call SetFocus(); to move an focus from tree view to listview ?
How does your command handler for the delete operation determine whether the treeview or the listview has focus? You haven't provided that code. As a user, my expectation would be that the delete operation should be deleting the item in the control that has focus. Though I guess a case could be made for deleting anything that is selected regardless of focus. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
I have an SDI application, with a splitter window that have in left view an CTreeView and right side an CListView.In each one I have some items. I override PreTranslateMessage in each one to be able on tab key to move focus from tree to view and viceversa :
BOOL CMyTree::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base classif(pMsg->message == WM\_KEYDOWN && pMsg->wParam == VK\_TAB) { CMyListView\* pView = (CMyListView\*)pChild->GetMyListView(); pView->SetFocus(); pView->GetListCtrl().SetItemState(0, LVIS\_SELECTED | LVIS\_FOCUSED, LVIS\_SELECTED | LVIS\_FOCUSED); } return TRUE; } return CTreeView::PreTranslateMessage(pMsg);
}
I see that the focus has moved. Somewhere in menu I have a delete menu that could delete items from tree or from listview. Let's say that I'm in treeview. I press tab and I see that the focus has moved on listview. When I try to delete an item I see that I delete an item from treeview not from list view .... so, from some reason, the focus remained in treeview ... The the deletion goes well only when I move the focus from tree on list view by click with mouse in list view ... My question is, is enough to call SetFocus(); to move an focus from tree view to listview ?
Looking at (ATL) code of mine for handling tabs, and which uses
GetDlgItem
rather thanSetFocus
, the only difference I can see is that I have a call:// Now select all like normal tab behaviour
SendMessage(hNew, EM_SETSEL, 0, -1);at the end. Presumably as my tabs have edit controls on and the cursor needs setting up. So unless there's a parallel with your views e.g. ensure, say, a node or list item has focus or is other wise set up, I'd agree with Chris and wonder about the code doing the deleting.
-
How does your command handler for the delete operation determine whether the treeview or the listview has focus? You haven't provided that code. As a user, my expectation would be that the delete operation should be deleting the item in the control that has focus. Though I guess a case could be made for deleting anything that is selected regardless of focus. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
Of course that program delete the item of window that have the focus ... the problem is : I am in the listview, I select 2 items, and when I go to main menu, click on delete item from menu, program wants to delete an tree view item, not list view items ... I try to make a little demo, to see what is happend.
-
Of course that program delete the item of window that have the focus ... the problem is : I am in the listview, I select 2 items, and when I go to main menu, click on delete item from menu, program wants to delete an tree view item, not list view items ... I try to make a little demo, to see what is happend.
If we could see your 'delete' code, that could help. That command handler code could delete items from either control. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
If we could see your 'delete' code, that could help. That command handler code could delete items from either control. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
void CMyTree::OnEditDelete()
{
// TODO: Add your command handler code hereCString sItem,sMessage; CTreeCtrl& Tree = GetTreeCtrl(); HTREEITEM hSelectedItem = Tree.GetSelectedItem(); if(! hSelectedItem)return; sItem = Tree.GetItemText(hSelectedItem); sMessage.Format(\_T("Are you sure you want to delete '%s' item ?"),sItem); if(IDYES != MessageBox(sMessage,NULL,MB\_YESNO | MB\_ICONWARNING))return; } // here I effectivelly delete an item into a serialized file and after that ... ( the tree view is loaded with serialized data ) theApp.UpdateAllViews(NULL,CMyApp::UH\_ITEM\_CHANGED);
}
the code for delete an item from list view is similar, but at the point when I have confirm message-box, the message said to me that want to delete item from listview, not from tree view .... I don't know if I'm was understable, but thank you anyway for your interest !!!!
-
void CMyTree::OnEditDelete()
{
// TODO: Add your command handler code hereCString sItem,sMessage; CTreeCtrl& Tree = GetTreeCtrl(); HTREEITEM hSelectedItem = Tree.GetSelectedItem(); if(! hSelectedItem)return; sItem = Tree.GetItemText(hSelectedItem); sMessage.Format(\_T("Are you sure you want to delete '%s' item ?"),sItem); if(IDYES != MessageBox(sMessage,NULL,MB\_YESNO | MB\_ICONWARNING))return; } // here I effectivelly delete an item into a serialized file and after that ... ( the tree view is loaded with serialized data ) theApp.UpdateAllViews(NULL,CMyApp::UH\_ITEM\_CHANGED);
}
the code for delete an item from list view is similar, but at the point when I have confirm message-box, the message said to me that want to delete item from listview, not from tree view .... I don't know if I'm was understable, but thank you anyway for your interest !!!!
[CListCtrl::DeleteItem] Deletes an item from a list view control.
CListCtrl* pmyListCtrl;
int nCount = pmyListCtrl->GetItemCount();
// Delete all of the items from the list view control.
for (int i=0;i < nCount;i++)
{
pmyListCtrl->DeleteItem(0);
}