473,467 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting selected element in List Box Control

Hi,
Iam new to VC++6.0.
I want to display selected item of the ListBox in a MessageBox. I know for
experience ppl it must be a kids play but for me who had worked in C# and
VB, it seems to be little different.
Can anyone write couple to lines of code for this?
Moreover, If I want to insert any element at the mth place of nth col in
list box of type Report. can I achieve it.

Thanks in anticipation.

Vin
Nov 17 '05 #1
3 1709
"Vijay" <he**********@yahoo.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Iam new to VC++6.0.
Glad to have you among us but ....

.... that tool is 6 or so years old.
I want to display selected item of the ListBox in a MessageBox.
Send the listbox a WM_GETCURSEL message. That will get you the index into
the list of the currently selected item. If the result is 0xFFFFFFFF (-1 as
a signed integer) then there is no selection. Then you send a LB_GETTEXTLEN
using the index of the item to get the length of the string. Then you insure
that you have a buffer at least one character larger (for the trailing 0
byte). Finally you send a LB_GETTEXT message to fetch the text into the
buffer.
Moreover, If I want to insert any element at the mth place of nth col in
list box of type Report. can I achieve it.


Check the docs for the LB_INSERTSTRING message.

Regards,
Will
Nov 17 '05 #2
Thanks for ur reply, But all the things jumped over my head. VC++ is really
a tough thing.
I have figured out one way to do this. It is as

LV_DISPINFO* pDispInfo = (LV_DISPINFO*) NMHDR;
int nPos = pDispInfo->item.iItem ;
POSITION Pos = m_List1.GetFirstSelectedItemPosition();
CString ListText = m_List1.GetItemText((int)Pos - 1, nPos);

I am able to fetch the fetch the selected Item in ListText . But Iam not
sure whether it is a gud process to do the things. If u hav a better one
don't hesitate to write it down.
Thanks
Vijay

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:u6**************@TK2MSFTNGP11.phx.gbl...
"Vijay" <he**********@yahoo.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Iam new to VC++6.0.


Glad to have you among us but ....

... that tool is 6 or so years old.
I want to display selected item of the ListBox in a MessageBox.


Send the listbox a WM_GETCURSEL message. That will get you the index into
the list of the currently selected item. If the result is 0xFFFFFFFF (-1
as a signed integer) then there is no selection. Then you send a
LB_GETTEXTLEN using the index of the item to get the length of the string.
Then you insure that you have a buffer at least one character larger (for
the trailing 0 byte). Finally you send a LB_GETTEXT message to fetch the
text into the buffer.
Moreover, If I want to insert any element at the mth place of nth col in
list box of type Report. can I achieve it.


Check the docs for the LB_INSERTSTRING message.

Regards,
Will

Nov 17 '05 #3
"Vijay" <he**********@yahoo.com> wrote in message
news:Ol**************@tk2msftngp13.phx.gbl...
Thanks for ur reply, But all the things jumped over my head. VC++ is
really a tough thing.
I sketched a way of handling a list box control because it is what you
mentioned in your post.
I have figured out one way to do this. It is as

LV_DISPINFO* pDispInfo = (LV_DISPINFO*) NMHDR;
int nPos = pDispInfo->item.iItem ;
POSITION Pos = m_List1.GetFirstSelectedItemPosition();
CString ListText = m_List1.GetItemText((int)Pos - 1, nPos);


This looks to me like you may be using a list view control as a virtual
listbox. If so, my reply is useless. In any event, it looks like you are
using MFC in which case you should probably post again in one of the groups
deveoted to it.

Regards,
Will
Nov 17 '05 #4

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

Similar topics

6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
4
by: planetthoughtful | last post by:
Hi All, I have a relatively simple web user control I've included in a page that simply presents 3 drop down lists and a submit button, that I use as a date picker (ie one list for day, one for...
6
by: Charleees | last post by:
Hi all, I have a DropDown and a TextBox just bekeow it... I have to get the selected value from dropdown and set it as textBox Text.. The thing is i have to do this Without PostBack..... ...
6
by: rishabhshrivastava | last post by:
Hey All, Can someone suggest me a way to get the values of CheckBox(es) selected in a CheckBoxList control using JAVASCRIPT. I am pasting my current code gere but its not working need some...
1
by: Roffers | last post by:
Okay I have a parent page, we'll call it parent.aspx and it holds the following two user controls <uc1:Box1 id="Box1" runat="server"></uc1:Box1<----THIS CONTAINS A DROP DOWN LIST <br>...
4
by: Mr. Wilson | last post by:
On this page (just a demo) I can’t get IE6 to auto-select the first item in the dynamically-generated drop-down menus. Well, that isn’t entirely true. Sometimes it works properly, but never on the...
11
by: Frank Rizzo | last post by:
I have a WebBrowser control on a .net 2.0 winforms app. I load up a page and want to get the selected entry of a dropdown. I can get the element: HtmlElement stationList =...
1
by: querry | last post by:
`Hi all, I am trying to get the selected radio button item in a radio button list using javascript. I am successful at doing this, but the problem is I have several Radio Button Lists, and the...
6
Frinavale
by: Frinavale | last post by:
I have a control that is supposed to allow the user to either allow or cancel what they were doing. When I apply this to a <select> element (or DropDownList), I cannot save the original value to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.