Listbox

  • Thread starter Thread starter Luna
  • Start date Start date
L

Luna

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
 
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: <[email protected]>
| >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
| >
| >
 
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. 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
 
Back
Top