Print Page | Close Window

CXTPControlBomboBox bug with Manual Updat

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=577
Printed Date: 06 March 2025 at 11:09am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPControlBomboBox bug with Manual Updat
Posted By: vladsch
Subject: CXTPControlBomboBox bug with Manual Updat
Date Posted: 28 March 2004 at 11:25am

Bug occurs if the CXTPControlComboBox control is set to manual update and SetDropDownListStyle(false).

To duplicate modify the CustomThemes sample to create a manual update combobox (make sure to delete the saved toolbars from the registry otherwise the old stored non-manual control will be used)

1. drop the list by clicking on the combobox
2. move the mouse so that an item is highlighted (other than the currently selected item)
3. click outside the list box so that the list box is closed without any selection being made. 

The combo box repaints with the new item even though it was not selected. Moving the mouse over the combobox causes it to repaint with the correct content.

The problem is caused during repaint while the list is dropped. The current selection for the list changes to follow the mouse movements so when GetText() method for the combobox is called from OnPaint while the list is dropped it uses the list's current selection to extract the string which will be the last hovered over item instead of the last selected item.

The solution that I used was to store the last selected item before poping up the list and restoring it when the popup is closed. This stored selection is modifed to the new selection in the OnSetSelected and OnExecute so that restoring the last selected value will not undo the new selection.

new or changed code is bold

CXTPControlComboBox.h add a new protected members to CXTPControlComboBox


    // Input:   bPopup - TRUE to set popup.
    // Returns: TRUE if successful; otherwise returns FALSE
    // Summary: This method is called to popup the control.
    virtual BOOL OnSetPopup(BOOL bPopup);

    // Summary: This method is called when the control is executed.
    virtual void OnExecute();

    int m_nLastSel;      // last user selected index, (used during display of list box)

in CXTPControlComboBox.cpp

in the Constructor Clear the new member to -1, not really needed but good practice


    m_nLastSel = -1;

Change/Add the following functions:


CString CXTPControlComboBox::GetText()
{
    int nSel = GetDroppedState() ? m_nLastSel : ((CListBox*)m_pCommandBar)->GetCurSel();
    CString str;
    if (nSel >= 0)
    ((CListBox*)m_pCommandBar)->GetText(nSel, str);
    return str;
}

void CXTPControlComboBox::OnSelChanged()
{
    m_nLastSel = GetCurSel();

    if (m_pEdit && m_pEdit->GetSafeHwnd()) m_pEdit->SetWindowText(GetText()); else m_strEditText = GetText();
    if (m_pParent && m_pParent->GetSafeHwnd()) m_pParent->Invalidate(FALSE);
}

BOOL CXTPControlComboBox::OnSetPopup(BOOL bPopup)
{
    if (bPopup)
    {
        m_nLastSel = GetCurSel();
    }
    else
    {
        SetCurSel(m_nLastSel);
    }

    return CXTPControlPopup::OnSetPopup(bPopup);
}

void CXTPControlComboBox::OnExecute()
{
    m_nLastSel = GetCurSel();
    CXTPControlPopup::OnExecute();
}

 




Replies:
Posted By: vladsch
Date Posted: 28 March 2004 at 1:56pm
Edited original post to add a call to base class in OnExecute.



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