Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I select a string from the drop down list of my combo-box that string is placed into the appropriate edit box and is highlighted (as expected). However, if I then decide to type my own string into the edit box, the first character I type replaces the existing highlighted string and the cursor jumps back to the starting position so that all subsequent typed characters precede the first. (e.g. If I type DC-10 what I get is C-10D). I suspect it has something to do with the focus created by the drop down select but why the cursor jump?

Thanks.


Here is some code to look at:

VB
ON_CBN_SELCHANGE(IDC_F4, OnSelChangeCombo)
    ON_CBN_EDITCHANGE(IDC_F4, OnSelChangeEditC)


C#
void CTab::OnSelChangeCombo()
{
    int m;

    UpdateData(true);

    m = ((CComboBox *) GetDlgItem(IDC_F4))->GetCurSel();
    if(m >= 0)
        ((CComboBox *) GetDlgItem(IDC_F4))->GetLBText(m, m_szETF4);
    else
        m_szETF4.Empty();

    UpdateData(FALSE);
}



C#
void CElecTab::OnSelChangeEditC()
{
    int     m;
    CString last4;

    last4 = m_szETF4;

    UpdateData(true);

    if(!m_szETF4.IsEmpty() && m_szETF4 != last4)
    {
        if((m = ((CComboBox *) GetDlgItem(IDC_F4))->FindStringExact(-1, last4)) != CB_ERR)
            ((CComboBox *) GetDlgItem(IDC_F4))->DeleteString(m);

        ((CComboBox *) GetDlgItem(IDC_F4))->AddString(m_szETF4);
    }

    UpdateData(FALSE);
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900