CXTEditListBox - editing an item |
Post Reply |
Author | |
aksen
Newbie Joined: 30 March 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
Posted: 30 March 2009 at 3:13am |
hi there
i'm using a CXTEditListBox to contain a list of objects that the user creates and can edit. the objects are uniquely identified by a name, and so i need the list box to enforce uniqueness. the way i would like it to work is that once they create a new entry in the list box, i will do validation to make sure the name is unique. if it isn't, i'd like the item in the list box to remain in edit mode, but i cannot seem to get this to happen. i did a search of the forum, and found a thread where someone wanted this same behaviour (see http://forum.codejock.com/forum_posts.asp?TID=5414). their solution was to post a user message back to the dialog, and call CXTEditListBox::EditItem() in the user message handler, as calling EditItem() in the list box handler did not work. i've tried this solution, and it still doesn't work - it appears to briefly make the item editable, before ending edit mode. how can i get this to work? i want the name validation to be done before the items are committed to the list box, as having duplicates in the list box creates confusion for the user (and for the programmer as well). thanks andrew |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
You can catch LBN_XT_NEWITEM and LBN_XT_LABELEDITEND, check item text - if dublicate - rename it to some "itemname1"
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
aksen
Newbie Joined: 30 March 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
|
hi Oleg
i already catch both of those - its where i currently do my checking. i've already done the renaming idea, but i don't really like it as a solution to the problem. is making an item editable in the list box just not possible? is EditItem() not meant to work like that? andrew |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
ok, what code you have now ? I need to check it.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
aksen
Newbie Joined: 30 March 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
|
hi Oleg
here are the relevant parts. if i leave the code as it is below, it doesn't do anything. if i change the code in OnListBoxNew() to post the UWM_EDIT_LIST_BOX_ITEM message instead of calling m_pEditListBoxControl->EditItem(m_nIndex), i get slightly different behaviour - it appears to briefly make the item in the list box editable, but then it immediately cancels that and goes back to normal selection mode. BEGIN_MESSAGE_MAP() ON_LBN_XT_NEWITEM(IDC_LIST1, OnListBoxNew) ON_MESSAGE(UWM_EDIT_LIST_BOX_ITEM, OnEditListBoxItem) END_MESSAGE_MAP() void CxyzDialog::OnListBoxNew() { int nCurrentSelection = m_pEditListBoxControl->GetCurrentIndex(); if (nCurrentSelection != -1) { CString sCurrentSelection; m_pEditListBoxControl->GetText(nCurrentSelection, sCurrentSelection); if (!Exists(sCurrentSelection)) SetName(sCurrentSelection); else { m_nIndex = nCurrentSelection; m_pEditListBoxControl->EditItem(m_nIndex); //PostMessage(UWM_EDIT_LIST_BOX_ITEM); } } } long CxyzDialog::OnEditListBoxItem(UINT wParam, long lParam) { m_pEditListBoxControl->EditItem(m_nIndex); return 0l; } thanks andrew |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hello,
Indeed CXTEditListBox in OnEndLabelEdit set selection and grab focus after it send message to parent - so your EditItem method will be canceled.
Think to create better deign - create new class CUniqueEditListBox : CXTEditListBox
add message map and catch
ON_LBN_XT_LABELEDITCANCEL(XT_IDC_LBOX_EDIT, OnEndLabelEdit)
in its OnEndLabelEdit handler first call base method and then check new item. - see original code of OnEndLabelEdit
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
aksen
Newbie Joined: 30 March 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
|
hi Oleg
you state that the end label edit message is setting the selection and grabbing focus after EditItem() has been called. i already catch ON_LBN_XT_LABELEDITEND, and unless i'm doing something wrong, this message isn't being issued when i finish creating a new label, only when i finish editing an existing label. is this correct? would deriving my own class from CXTEditListBox change this behaviour? thanks andrew |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |