Results 1 to 6 of 6

Thread: [RESOLVED] display a two dimensional Array in the listbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    19

    Resolved [RESOLVED] display a two dimensional Array in the listbox

    Hi guys,

    I'm trying to display in a list box a two dimensional array using format string.
    The information for my array I'm getting from an external file.
    this is what I have, and I don't know how to fix this.
    Code:
    Sub DisplaySeatChart()
    
            Dim fmtstr As String = "{0, -15}{1,-15}{2,20}{3,-15}{4,-15}"
            For i = 0 To 9
                For j = 0 To 3
    
                    lstSeatChart.Items.Add(String.Format(fmtstr, SeatChart(i, 0), SeatChart(i, 1), "|", SeatChart(i, 2), SeatChart(i, 3)))
                Next
            Next
    end Sub
    I want to make it look like this

    00 01 | 02 03
    10 11 | 12 13
    20 21 | 22 23
    etc..

    Tks

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: display a two dimensional Array in the listbox

    Code:
    Dim formatstring As String = "{0}{1} | {2}{3}"
    
    For i = 0 To 3
        Dim elems() As Object = { _
                    SeatChart(i, 0), _
                    SeatChart(i, 1), _
                    SeatChart(i, 2), _
                    SeatChart(i, 3) }
    
        lstSeatChart.Items.Add(String.Format(formatstring, elems ))
        
    Next

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: display a two dimensional Array in the listbox

    I don't think we're getting the whole story. Your format string implies you want something more than your example shows. Do you actually want each value padded to 15 characters? Perhaps you need provide a proper example. This time wrap it in CODE tags to maintain formatting, which the browser will strip out otherwise.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    19

    Re: display a two dimensional Array in the listbox

    Thank you guys for your comments.

    The display is very simple. I do not need the 15 characters, I just for show the data Uniform.

    My array will have only "." in all the columns when the form is load, then I will have to replace the "." for a "X" when somebody enter a name in a text box. That name also will be store in another (waiting list) and I will dislay this list in a different ListBox.

    The purpose of this is to have an airline reservation program.

    Also I will need to be able to delete a passenger if they cancel the reservation, and allocate the one that was in a the waiting list box (if any) to the new seat available, and deleted from the waiting list.


    cicatrix

    Thank you for your input, but we did not cover Object in this class and I don't think I'm allow to use it.

    Thanks again for your input

  5. #5
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: display a two dimensional Array in the listbox

    Change it to Integer then:

    Code:
     Dim elems() As Integer = { _
                    SeatChart(i, 0), _
                    SeatChart(i, 1), _
                    SeatChart(i, 2), _
                    SeatChart(i, 3) }

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    19

    Wink Re: display a two dimensional Array in the listbox

    cicatrix

    Thank you.
    I will keep working on the rest of the project.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width