473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

getting value from listbox

I am trying to retrieve a selected value from a listbox and store it in
a string (char[]) variable. I am using the following code:

calibIndex=SendMessage(hWnd,(UINT)IDC_LIST_CALIBOP TS,(WPARAM)0,
LPARAM)0);
SendMessage(hWnd,(UINT)LB_GETTEXT,(WPARAM)calibInd ex,(LPARAM)selectedCalib);

Where IDC_LIST_CALIBOPTS is the list and selectedCalib is the variable
where I want the value to go.

This does not work and when I look at the value of selectedCalib it is
"[rvЩ]" and not "Calibration1" as I expected.

Can anybody help?

Thank you

Jul 23 '05 #1
4 5609
The first statement:
calibIndex=SendMessage(hWnd,(UINT)IDC_LIST_CALIBOP TS,(WPARAM)0,
LPARAM)0);

is incorrect.
To get the selected index, use:

calibIndex=SendMessage(hWnd,(UINT)LB_GETSEL,(WPARA M)0,
LPARAM)0);

hWnd is the handle to the Listbox control. It can be obtained from:
hWnd = GetDlgItem (hParentWnd, IDC_LIST_CALIBOPTS);
where hParentWnd is the handle of the dialog/window hosting the Listbox.

The second statement in your code is correct. Remember that hWnd is the
handle to the listbox control and not to the parent window/dialog.
Jul 23 '05 #2
Thank You

That solved the problem. Was getting mixed up with handle to the
control and handle to the parent window.
One more, do you know why using the following to fill the list box will
make the first item in the list blank?

inputfile.getline(sectionName, 50);
SendMessage(hwndlist, LB_ADDSTRING, 0, (LPARAM) sectionName); //populate

Jul 23 '05 #3

"Nahappan SM" <sm*****@hotmail.com> wrote in message
news:Fu****************@news.cpqcorp.net...
The first statement:
calibIndex=SendMessage(hWnd,(UINT)IDC_LIST_CALIBOP TS,(WPARAM)0,
LPARAM)0);

is incorrect.
To get the selected index, use:

calibIndex=SendMessage(hWnd,(UINT)LB_GETSEL,(WPARA M)0,
LPARAM)0);

hWnd is the handle to the Listbox control. It can be obtained from:
hWnd = GetDlgItem (hParentWnd, IDC_LIST_CALIBOPTS);
where hParentWnd is the handle of the dialog/window hosting the Listbox.

The second statement in your code is correct. Remember that hWnd is the
handle to the listbox control and not to the parent window/dialog.


Please refrain from discussing MFC or other platform-specific code here.
Listboxes, dialogs, etc., are not part of the standard C++ language and
off-topic in this newsgroup. Questions regarding MFC should be directed to
microsoft.public.vc.mfc. Answering them here only encourages more off-topic
questions.

-Howard

Jul 23 '05 #4
sorry

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Eddy Scheire | last post by:
Hi all, I've got this listbox and this text field on an ASP page. Now I want the item I click on in the listbox to appear in the text field and I can't find the code nowhere for what seems to me...
2
by: Remco Groot Beumer | last post by:
Hello, I created a program in which I use modules and classmodules for setting my variables. For example when I need to set the customerID in a variable I use something like: ...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
2
by: Allan Horwitz | last post by:
When I try to reference the lstproducts.selecteditem.value using autopostback from the lstproducts listbox I get an error? How can I fix my code to get the selected value from the lstproducts...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
0
by: Sosh | last post by:
Hi, I'm having a bit of a job getting a handle on a ListBox that i've placed in one column of the footer in a DataGrid. Here's what I've tried so far: - Declaring a protected listbox (with...
10
by: Ben | last post by:
Hi Im trying to get the value from a listbox, i have the below code to get the text: txtEntity.Text = ListBox1.Text But do not seem to be able to retrieve the data that i set as the value...
4
by: Karen Hill | last post by:
I've got a list box that has two columns. I would like to get the value of the first column of the user selected row. How would I do that? It is not a multiselect listbox. PS Whats the...
2
by: php_Boi | last post by:
i have designed an application that is a dynamic submission form. i have text fields and listboxes. now i am able to retain the values of the listboxes when i populate the listbox "manually"(single...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.