Solved

Choosing names from  list box in Visual C++

Posted on 2000-04-18
2
154 Views
Last Modified: 2010-04-02
I have a problem with list box in visual c++. After å name search I show the results in a list box, but I don't know how I can pick out the right name?
I use xxx.GetText() but then I only get the name displayed in the list box.. I want to get the data that is linked to the name displayed in the list box. (The data linked to each name is adress, phone nr and so on...)
Is there a command that returns the line nr in the list box? Or returns a path to the data linked to the name I clicked on?
0
Comment
Question by:andreas75
2 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2726110
How was the data loaded into the listbox. Was the data associted with each entry using SetItemData or SetItemDataPtr if so then you can use GetItemData or GetItemDataPtr.

If you have the name can you walk the list of results (the ones you used to load the listbox) and find a match and then get the name, number etc

Sorry I can't be more exact without more info :)
0
 
LVL 1

Accepted Solution

by:
tvanceplus earned 100 total points
ID: 2727105
Here is some code where the resource ID for your list box is IDC_LIST.

int nr;

nr=getitemtoget();

....

CListBox* pList;
pList=(CListBox*)GetDlgItem(IDC_LIST);

CString text;

pList->GetLBText(nr,text);

Now text is whatever text was on line nr or the list box. This also works for combo boxes.

Good Luck!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now