471,075 Members | 910 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Listbox

Hi,

I want to pass the values that have been chosen from a
few comboboxes into a listbox as a single entry.

how do i do this??

this is what i tried... it will probably give u some
indication of what im trying to achieve:

Dim ChosenDate As Date
ChosenDate = dtpRoomDate.Value()
Dim ChosenRoom As String
ChosenRoom = CBoxRoomNames.SelectedItem
Dim ChosenLayout As String
ChosenLayout = CBoxLayout.SelectedItem
Dim ChosenSession As String
ChosenSession = CBoxSession.SelectedItem
Dim ChosenGuestNo As Int32
ChosenGuestNo = txtNoOfGuests.Text

LBoxSelRooms.Items.Add(ChosenDate, ChosenRoom,
ChosenLayout, ChosenSession, ChosenGuestNo)
of course this does not work!! I want all the values
passed into the same row. is this possible or would i be
better off using another control?

Thx for your time

Jul 21 '05 #1
2 2041
First, if you want the data to appear in separate columns, use a ListView control with the view property set to View.Details. I
think you're saying you want everything to appear as a single string in one column, though. In this case, using a ListBox will
work. One way to acheive this is to format all the data you want to add to the list box as a single string, and then add this
string to the listbox. For example, you could modify your call to LBoxSelRooms.Items.Add as follows:

Dim FullDescription As String
FullDescription = String.Format("{0}, {1}, {2}, {3}, {4}", ChosenDate, ChosenRoom, ChosenLayout, ChosenSession,
ChosenGuestNo)
LBoxSelRooms.Items.Add(FullDescription)

To modify how the data appears, change the formatting string in the above call to String.Format.

Another slightly more complex approach would be to create a class to encapsulate the data you want to add, and then
override the ToString method in this class to return the formatted string you want to appear in the list box. You would then
create an instance of this class and add it to the listbox. If you need to pass this information to other parts of your
application, this approach could result in cleaner, more maintainable code.

Thanks,
Grayson

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| >Content-Class: urn:content-classes:message
| >From: "Luna" <s@u>
| >Sender: "Luna" <s@u>
| >Subject: Listbox
| >Date: Sun, 16 Nov 2003 04:31:30 -0800
| >Lines: 31
| >Message-ID: <04****************************@phx.gbl>
| >MIME-Version: 1.0
| >Content-Type: text/plain;
| > charset="iso-8859-1"
| >Content-Transfer-Encoding: 7bit
| >X-Newsreader: Microsoft CDO for Windows 2000
| >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| >Thread-Index: AcOsPZASt/3KcVMcQTaF6Giop2UJOA==
| >Newsgroups: microsoft.public.dotnet.general
| >Path: cpmsftngxa06.phx.gbl
| >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:115760
| >NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| >X-Tomcat-NG: microsoft.public.dotnet.general
| >
| >Hi,
| >
| >I want to pass the values that have been chosen from a
| >few comboboxes into a listbox as a single entry.
| >
| >how do i do this??
| >
| >this is what i tried... it will probably give u some
| >indication of what im trying to achieve:
| >
| >Dim ChosenDate As Date
| > ChosenDate = dtpRoomDate.Value()
| > Dim ChosenRoom As String
| > ChosenRoom = CBoxRoomNames.SelectedItem
| > Dim ChosenLayout As String
| > ChosenLayout = CBoxLayout.SelectedItem
| > Dim ChosenSession As String
| > ChosenSession = CBoxSession.SelectedItem
| > Dim ChosenGuestNo As Int32
| > ChosenGuestNo = txtNoOfGuests.Text
| >
| >LBoxSelRooms.Items.Add(ChosenDate, ChosenRoom,
| >ChosenLayout, ChosenSession, ChosenGuestNo)
| >
| >
| >of course this does not work!! I want all the values
| >passed into the same row. is this possible or would i be
| >better off using another control?
| >
| >Thx for your time
| >
| >
Jul 21 '05 #2
Hi,

If i use the listbox,can i still refence the coloumns
indivually afterwords or will all the columns be stored
as one long string?

I need to be able to access each individual column after
they have been put into the listbox (or any other control
that u reccomend).

thx
-----Original Message-----
First, if you want the data to appear in separate columns, use a ListView control with the view property
set to View.Details. Ithink you're saying you want everything to appear as a single string in one column, though. In this case, using
a ListBox willwork. One way to acheive this is to format all the data you want to add to the list box as a single string, and
then add thisstring to the listbox. For example, you could modify your call to LBoxSelRooms.Items.Add as follows:
Dim FullDescription As String
FullDescription = String.Format("{0}, {1}, {2}, {3}, {4}", ChosenDate, ChosenRoom, ChosenLayout,
ChosenSession,ChosenGuestNo)
LBoxSelRooms.Items.Add(FullDescription)

To modify how the data appears, change the formatting string in the above call to String.Format.
Another slightly more complex approach would be to create a class to encapsulate the data you want to add,
and thenoverride the ToString method in this class to return the formatted string you want to appear in the list box. You
would thencreate an instance of this class and add it to the listbox. If you need to pass this information to other
parts of yourapplication, this approach could result in cleaner, more maintainable code.
Thanks,
Grayson

This posting is provided "AS IS" with no warranties, and confers no rights.--------------------
| >Content-Class: urn:content-classes:message
| >From: "Luna" <s@u>
| >Sender: "Luna" <s@u>
| >Subject: Listbox
| >Date: Sun, 16 Nov 2003 04:31:30 -0800
| >Lines: 31
| >Message-ID: <04****************************@phx.gbl>
| >MIME-Version: 1.0
| >Content-Type: text/plain;
| > charset="iso-8859-1"
| >Content-Transfer-Encoding: 7bit
| >X-Newsreader: Microsoft CDO for Windows 2000
| >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300| >Thread-Index: AcOsPZASt/3KcVMcQTaF6Giop2UJOA==
| >Newsgroups: microsoft.public.dotnet.general
| >Path: cpmsftngxa06.phx.gbl
| >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:115760| >NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| >X-Tomcat-NG: microsoft.public.dotnet.general
| >
| >Hi,
| >
| >I want to pass the values that have been chosen from a| >few comboboxes into a listbox as a single entry.
| >
| >how do i do this??
| >
| >this is what i tried... it will probably give u some
| >indication of what im trying to achieve:
| >
| >Dim ChosenDate As Date
| > ChosenDate = dtpRoomDate.Value()
| > Dim ChosenRoom As String
| > ChosenRoom = CBoxRoomNames.SelectedItem
| > Dim ChosenLayout As String
| > ChosenLayout = CBoxLayout.SelectedItem
| > Dim ChosenSession As String
| > ChosenSession = CBoxSession.SelectedItem
| > Dim ChosenGuestNo As Int32
| > ChosenGuestNo = txtNoOfGuests.Text
| >
| >LBoxSelRooms.Items.Add(ChosenDate, ChosenRoom,
| >ChosenLayout, ChosenSession, ChosenGuestNo)
| >
| >
| >of course this does not work!! I want all the values
| >passed into the same row. is this possible or would i be| >better off using another control?
| >
| >Thx for your time
| >
| >
.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by amber | last post: by
3 posts views Thread by Paul T. Rong | last post: by
8 posts views Thread by Oddball | last post: by
6 posts views Thread by Chris Leuty | last post: by
7 posts views Thread by Dave | last post: by
3 posts views Thread by Ali Chambers | last post: by
reply views Thread by leo001 | last post: by

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.