Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTEditListBox - editing an item
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTEditListBox - editing an item

 Post Reply Post Reply
Author
Message
aksen View Drop Down
Newbie
Newbie


Joined: 30 March 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote aksen Quote  Post ReplyReply Direct Link To This Post Topic: CXTEditListBox - editing an item
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 30 March 2009 at 5:04am
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
Back to Top
aksen View Drop Down
Newbie
Newbie


Joined: 30 March 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote aksen Quote  Post ReplyReply Direct Link To This Post Posted: 30 March 2009 at 5:25am
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 30 March 2009 at 12:35pm
Hi,
 
ok, what code you have now ? I need to check it.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
aksen View Drop Down
Newbie
Newbie


Joined: 30 March 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote aksen Quote  Post ReplyReply Direct Link To This Post Posted: 30 March 2009 at 8:14pm
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 31 March 2009 at 2:19am
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
Back to Top
aksen View Drop Down
Newbie
Newbie


Joined: 30 March 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote aksen Quote  Post ReplyReply Direct Link To This Post Posted: 31 March 2009 at 10:20pm
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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.