Listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luna

    #1

    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.Val ue()
    Dim ChosenRoom As String
    ChosenRoom = CBoxRoomNames.S electedItem
    Dim ChosenLayout As String
    ChosenLayout = CBoxLayout.Sele ctedItem
    Dim ChosenSession As String
    ChosenSession = CBoxSession.Sel ectedItem
    Dim ChosenGuestNo As Int32
    ChosenGuestNo = txtNoOfGuests.T ext

    LBoxSelRooms.It ems.Add(ChosenD ate, 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

  • Grayson Myers [MSFT]

    #2
    RE: Listbox

    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.It ems.Add as follows:

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

    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: <049601c3ac3d$9 014a340$a401280 a@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/3KcVMcQTaF6Giop 2UJOA==
    | >Newsgroups: microsoft.publi c.dotnet.genera l
    | >Path: cpmsftngxa06.ph x.gbl
    | >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:115760
    | >NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
    | >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
    | >
    | >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.Val ue()
    | > Dim ChosenRoom As String
    | > ChosenRoom = CBoxRoomNames.S electedItem
    | > Dim ChosenLayout As String
    | > ChosenLayout = CBoxLayout.Sele ctedItem
    | > Dim ChosenSession As String
    | > ChosenSession = CBoxSession.Sel ectedItem
    | > Dim ChosenGuestNo As Int32
    | > ChosenGuestNo = txtNoOfGuests.T ext
    | >
    | >LBoxSelRooms.I tems.Add(Chosen Date, 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
    | >
    | >


    Comment

    • Luna

      #3
      RE: Listbox

      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
      [color=blue]
      >-----Original Message-----
      >First, if you want the data to appear in separate[/color]
      columns, use a ListView control with the view property
      set to View.Details. I[color=blue]
      >think you're saying you want everything to appear as a[/color]
      single string in one column, though. In this case, using
      a ListBox will[color=blue]
      >work. One way to acheive this is to format all the data[/color]
      you want to add to the list box as a single string, and
      then add this[color=blue]
      >string to the listbox. For example, you could modify[/color]
      your call to LBoxSelRooms.It ems.Add as follows:[color=blue]
      >
      > Dim FullDescription As String
      > FullDescription = String.Format(" {0}, {1}, {2},[/color]
      {3}, {4}", ChosenDate, ChosenRoom, ChosenLayout,
      ChosenSession,[color=blue]
      >ChosenGuestN o)
      > LBoxSelRooms.It ems.Add(FullDes cription)
      >
      >To modify how the data appears, change the formatting[/color]
      string in the above call to String.Format.[color=blue]
      >
      >Another slightly more complex approach would be to[/color]
      create a class to encapsulate the data you want to add,
      and then[color=blue]
      >override the ToString method in this class to return the[/color]
      formatted string you want to appear in the list box. You
      would then[color=blue]
      >create an instance of this class and add it to the[/color]
      listbox. If you need to pass this information to other
      parts of your[color=blue]
      >application, this approach could result in cleaner, more[/color]
      maintainable code.[color=blue]
      >
      >Thanks,
      >Grayson
      >
      >This posting is provided "AS IS" with no warranties, and[/color]
      confers no rights.[color=blue]
      >--------------------
      >| >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: <049601c3ac3d$9 014a340$a401280 a@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[/color]
      V5.50.4910.0300[color=blue]
      >| >Thread-Index: AcOsPZASt/3KcVMcQTaF6Giop 2UJOA==
      >| >Newsgroups: microsoft.publi c.dotnet.genera l
      >| >Path: cpmsftngxa06.ph x.gbl
      >| >Xref: cpmsftngxa06.ph x.gbl[/color]
      microsoft.publi c.dotnet.genera l:115760[color=blue]
      >| >NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
      >| >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
      >| >
      >| >Hi,
      >| >
      >| >I want to pass the values that have been chosen from[/color]
      a[color=blue]
      >| >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.Val ue()
      >| > Dim ChosenRoom As String
      >| > ChosenRoom = CBoxRoomNames.S electedItem
      >| > Dim ChosenLayout As String
      >| > ChosenLayout = CBoxLayout.Sele ctedItem
      >| > Dim ChosenSession As String
      >| > ChosenSession = CBoxSession.Sel ectedItem
      >| > Dim ChosenGuestNo As Int32
      >| > ChosenGuestNo = txtNoOfGuests.T ext
      >| >
      >| >LBoxSelRooms.I tems.Add(Chosen Date, 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[/color]
      be[color=blue]
      >| >better off using another control?
      >| >
      >| >Thx for your time
      >| >
      >| >
      >
      >
      >.
      >[/color]

      Comment

      Working...