CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    226

    Removing Items From A Combo Box

    I'm trying to write a function to remove an item from a combo box. How it works is you select a item in the drop down box and then click remove. It this point a window will come up and ask "Are you sure you want to remove this item." This item will be the text of the combo box list item to be removed. However, I can't quite get the correct text for the item. I couldn't find a function in the documentation that will get the text of the selected item so I tried to using the GetWindowText() function. That will return the text of the first item in the list. Even after it's been removed. Here is the function:

    void CAddRemoveGroupDlg::OnRemove()
    {
    // TODO: Add your control notification handler code here
    CString Text;
    CString Message;
    m_Group.GetWindowText(Text);
    Message = "Are you sure you want to remove the group '" + Text;
    Message += "'?";
    if(AfxMessageBox(Message, MB_YESNO) == IDYES)
    {
    m_Groups.DeleteString(m_Groups.GetCurSel());
    m_Groups.SetCurSel(0);
    }
    }



    Does anyone know how to get this to work?

    Scott MacMaster
    ______________________
    http://welcome.to/scottweb

  2. #2
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: Removing Items From A Combo Box

    Have you looked at CComboBox::GetLBText()?

    CString szText;

    int iIndex = m_Group.GetCurSel();

    m_Group.GetLBText(iIndex, szText);

    Rail

    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    [email protected]
    http://home.earthlink.net/~railro/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured