Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to link list box and the edit box for a particular application,
If i select some item in the list box, its corresponding value should be displayed in the text box and allow to modify..

Please Help me out
Posted

1 solution

Add an LBN_SELCHANGE[^] handler to your dialog class that updates the edit control with the newly selected item:
C++
CMyDialog::OnSelChange()
{
    int nSel = m_ListBox.GetCurSel();
    if (nSel != LB_ERR)
    {
        CString strText;
        m_ListBox.GetText(nSel, strText);
        m_EditBox.SetWindowText(strText);
    }
}
 
Share this answer
 
v2
Comments
Member 11493554 9-Mar-15 7:05am    
SetText is not working.!!
Please provide a sample program..
Jochen Arndt 9-Mar-15 7:11am    
Sorry. Must be SetWindowText of course.
Member 11493554 9-Mar-15 7:25am    
SetWindowText is also not working

Jochen Arndt 9-Mar-15 7:31am    
I just checked it here and it is working for me.
Is your handler called (check it by setting a breakpoint)?

If not, you must set the LBS_NOTIFY style for your list box as noted in the MSDN entry for LBN_SELCHANGE (see the link from my answer).

Note also that the handler is not called if you set the selection programmatically (e.g. with SetCurSel).
Member 11493554 9-Mar-15 7:46am    
Im using CIniFile Class method

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