[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
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
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.
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
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) }
Re: display a two dimensional Array in the listbox
cicatrix
Thank you.
I will keep working on the rest of the project. :wave::thumb: