Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a list control on my dialog-box which contain list of names. when one particular name is selcted then display it in editbox control. How to do this in mfc? better if provide one simple code example.
Posted
Updated 14-Jan-16 23:08pm
v2

This CodeProject article provides comprehensive overview: Using the CListBox control[^].

Pay attention for the notification message LBN_SELCHANGE in the section "Handling CListBox Messages".

Please see: LBN_SELCHANGE notification code (Windows)[^].

As to the edit box, you can use the class CEdit. Using is the way you probably does not need additional explanations: CEdit Class[^].

Basically, this is all you need to know.

Good luck.
—SA
 
Share this answer
 
v2
Comments
Kishor-KW 15-Jan-16 1:26am    
hi SA,
I already go through that article it is nice but more functionality are there its take time to get understand, I want solution soon. just simple solution. I will go into detail after. Thank you for Solution
Sergey Alexandrovich Kryukov 15-Jan-16 2:10am    
This is not a reply, this is a solution. This is all you really need. Yes, it needs some time and effort, but this is unavoidable. Indeed, the problem is quite simple. If you want the solution soon, start to work intensively. :-)

If you have some follow-up question, I'll try to answer.

—SA
Kishor-KW 15-Jan-16 3:32am    
but it is about a listbox control I am asking about list control.
Sergey Alexandrovich Kryukov 15-Jan-16 8:13am    
Isn't it the same? or do you mean list view control? You have to define clearly what you need.
—SA
 
Share this answer
 
Comments
Kishor-KW 17-Jan-16 0:52am    
yes I exactly want this. but I want the selected value's Text to store in CString type variable. How to get the text of selected item of the list control
Kishor-KW 17-Jan-16 1:54am    
I got the solution using following code means I got the text of selected value.

void Cselect_product::OnItemchangedListCategory(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here





CListCtrl* pListCtrl = (CListCtrl *) GetDlgItem(IDC_ListCategory);


POSITION pos = m_klist.GetFirstSelectedItemPosition ();
if (pos == NULL)
TRACE0 ("No items were selected! \n");
else
{
while (pos)
{
int nItem = m_klist.GetNextSelectedItem (pos);
TRACE1 ("Item %d was selected! \n", nItem);
//you could do your own processing on nItem here

strText = m_klist.GetItemText(nItem, 0);
}
}








*pResult = 0;
}


but list control's view property is set to the List at that time I want all this operation when view property of list control is Report.

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