Print Page | Close Window

CXTEditListBox - editing an item

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=13848
Printed Date: 25 June 2024 at 8:14pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTEditListBox - editing an item
Posted By: aksen
Subject: CXTEditListBox - editing an item
Date 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&KW=CXTEditListBox - 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



Replies:
Posted By: Oleg
Date 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


Posted By: aksen
Date 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


Posted By: Oleg
Date 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


Posted By: aksen
Date 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


Posted By: Oleg
Date 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


Posted By: aksen
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net