
list box text to edit box
OK, there are a couple approaches. For example, forget any solution
that uses UpdateData; the mechanism is not needed.
void CFormulas_2Dlg::OnSelChangeL()
{
int n = m_E.GetCurSel();
if(n < 0)
return; // no selection
CString s;
m_E.GetLBText(n, s);
The string s now contains the text you want. But a more intersting
thing to do is that when you load the information into the list box,
you do so from a structure (note you said ListBox, not ListCtrl, so
there is no NM_CLICK event for a ListBox, and only a EN_SELCHANGE
event). So I would load it up by doing something like
for(i = 0; ... ; i++
{
int n = m_E.AddString(data[i].text);
m_E.SetItemDataPtr(n, &data[i]);
}
Now that this has done is put a pointer to your data table in every
listbox entry. That entry contains the text you wanted to add, and all
the related information you want to associate with it. Then, in the
OnSelChange handler, you do
MyData * data = (MyData *)m_E.GetItemDataPtr(n);
then you can extract whatever you want from your data structure and
display it.
If you are doing this with a CListCtrl, there is also an ItemData
field associated with each entry.
joe
On Fri, 19 Oct 2001 13:09:27 GMT, "WorkWithMe\(TRUE\)"
Quote:
>Hi,
>Sorry for the trouble, i am a newbie at this stuff so please bear with me!
>After i get =NM_CLICK trapped and everything declared, where specifically do
>the put the SetDlgItemText and the text for it? I have tried lotsa places
>and none worked. Here is what i have now:
>void CFormulas_2Dlg::OnL() //OnL is for the list box
>{
> // TODO: Add your control notification handler code here
> //m_E is the edit box
> m_E.SetDlgItemText(1, "test");
> m_E.SetDlgItemText(2, "test2");
>}
>void CFormulas_2Dlg::OnE()
>{
>I have tried switching the E to L and still didn't work, and i have tried
>put the m_E.SetDlgItemText(1, "test");
>under one of the strings in the list box like: m_L.AddString("Example");
>Nothing worked. What am i doing wrong? Thank you for helping!
>Randy
>> Hi Randy,
>> Try to trap the NM_CLICK notification message and use SetDlgItemText to
>output the specified text to the Edit Box.
>> For more information about how to trap NM_CLICK message, please visit:
>> http://support.microsoft.com/support/kb/articles/Q147/8/42.ASP
>> I hope this helps. If you have additional questions on this topic, please
>reply to this posting.
>> Need quick answers to questions like these? The Microsoft Knowledge Base
>provides a wealth of information that you can use to troubleshoot a problem
>or answer a
>> question! It's located at http://support.microsoft.com/support/c.asp?M=F>.
>> This posting is provided "AS IS" with no warranties, and confers no
>rights. You assume all risk for your use. Copy Right, 2001 Microsoft
>Corporation. All rights reserved.
>> Regards,
>> Felix Wu
>> --------------------
>> >Newsgroups: microsoft.public.vc.mfc
>> >Subject: list box text to edit box
>> >Lines: 11
>> >X-Priority: 3
>> >X-MSMail-Priority: Normal
>> >X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
>> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>> >Date: Thu, 18 Oct 2001 21:47:53 GMT
>> >NNTP-Posting-Host: 24.5.188.39
>> >X-Trace: news1.rdc1.ga.home.com 1003441673 24.5.188.39 (Thu, 18 Oct 2001
>14:47:53 PDT)
>> >NNTP-Posting-Date: Thu, 18 Oct 2001 14:47:53 PDT
>http://home.com/faster
>> >Path:
>cppssbbsa01.microsoft.com!news-out.cwix.com!newsfeed.cwix.com!newsfeed.direc
>t.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!
>> news1.rdc1.ga.home.com.POSTED!not-for-mail
>> >Xref: cppssbbsa01.microsoft.com microsoft.public.vc.mfc:298408
>> >X-Tomcat-NG: microsoft.public.vc.mfc
>> >can anyone tell me how to specify text for a selection in a list box? for
>> >example, if i click on the "United States" selection in the listbox, then
>> >some specified text about it or something will appear automatically in
>the
>> >edit box. i'm also having trouble getting the text to appear on the edit
>box
>> >from the list box. can anyone help me out? the best help i could find on
>a
>> >website was how to get an item from an edit box to a list box. Thank you
>in
>> >advance!
>> >Randy
Joseph M. Newcomer [MVP]
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm