CListBox..... HELP! 
Author Message
 CListBox..... HELP!

Hi,

I can't seem to find out HOW to get the selected text string from a ListBox control. What I want to do is select a
string in my ListBox, and then send it to a textbox. I can send text to a textbox with no problem, but getting the text
string from the ListBox is proving to be difficult for me. Anyone have any ideas?

Thanks!
Glen



Wed, 14 Nov 2001 03:00:00 GMT  
 CListBox..... HELP!
Hi,
Assuming that the list box is single selection (properties dialog in the
dialog resource editor)

CString strOut;
CListBox* pListBox = (CListBox*) GetDlgItem(IDC...);
int nSel = pListBox->GetCurSel();
if (nSel != LB_ERR) {
  pListBox->GetText(nSel, strOut);

Quote:
}

strOut is the string.  Not compiled, but should work ok.

--
Adrian O' Neill
http://www.quiver.freeserve.co.uk


Quote:
> Hi,

> I can't seem to find out HOW to get the selected text string from a

ListBox control. What I want to do is select a
Quote:
> string in my ListBox, and then send it to a textbox. I can send text to a

textbox with no problem, but getting the text
Quote:
> string from the ListBox is proving to be difficult for me. Anyone have any
ideas?

> Thanks!
> Glen



Wed, 14 Nov 2001 03:00:00 GMT  
 CListBox..... HELP!
Better still, use ClassWizard to create control variables. Rule of
thumb: if you write more than one GetDlgItem per year, you are not
using MFC properly. I use a c_ prefix instead of the m_ prefix when
I'm creating a control variable.

CString s;
int sel = c_ListBox.GetCurSel();
if(sel != LB_ERR)
  {
    c_ListBox.GetText(sel, s);
    c_EditControl.SetWindowText(s);
   }

I find this code far easier to write and use.
                                joe

On Sat, 29 May 1999 23:45:56 +0100, "Adrian O' Neill"

Quote:

>Hi,
>Assuming that the list box is single selection (properties dialog in the
>dialog resource editor)

>CString strOut;
>CListBox* pListBox = (CListBox*) GetDlgItem(IDC...);
>int nSel = pListBox->GetCurSel();
>if (nSel != LB_ERR) {
>  pListBox->GetText(nSel, strOut);
>}

>strOut is the string.  Not compiled, but should work ok.

Joseph M. Newcomer

http://www3.pgh.net/~newcomer


Sat, 17 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CListbox::SetItemDataPtr(), CListBox::GetItemDataPtr()

2. CListBox Help?

3. CListBox -- please help!

4. Repaint CListbox With Filenames Help

5. CListBox help

6. CListBox PreCreateWindow HELP!

7. CListBox.SetTabStop() Help

8. need help with scrolling in CListBox

9. CListBox and AddString :: HELP

10. HELP: CListBox:SetItemDataPtr

11. *** Strange CListBox problems: Expert help needed!

12. Help - CListBox, Disabling User Multiselection

 

 
Powered by phpBB® Forum Software