Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 列表框格式_Vb.net_Visual Studio 2012_Listbox_Formatting_Format - Fatal编程技术网

Vb.net 列表框格式

Vb.net 列表框格式,vb.net,visual-studio-2012,listbox,formatting,format,Vb.net,Visual Studio 2012,Listbox,Formatting,Format,我想格式化我的列表框,以便输出像这样 这是一种方法,而不是主要形式tho: Public Function GetSeatInfoStrings(ByVal choice As DisplayOptions, ByRef strSeatInfoStrings As String()) As Integer Dim count As Integer = GetNumOfSeats(choice) If (

我想格式化我的列表框,以便输出像这样

这是一种方法,而不是主要形式tho:

Public Function GetSeatInfoStrings(ByVal choice As DisplayOptions,
                                      ByRef strSeatInfoStrings As String()) As Integer
    Dim count As Integer = GetNumOfSeats(choice)

    If (count <= 0) Then
        Return 0
    End If

    strSeatInfoStrings = New String(count - 1) {}

    Dim StrReservation As String = ""

    strSeatInfoStrings = New String(count - 1) {}

    Dim i As Integer = 0 'counter for return array 

    'is the element corresponding with the index empty 
    For index As Integer = 0 To m_totNumOfSeats - 1

        Dim strName As String = ""
        Dim reserved As Boolean = Not String.IsNullOrEmpty(m_nameList(index))

        'if the criteria below are not met, skip to add info in the array
        If (choice = DisplayOptions.AllSeats) Or
            (reserved And choice = DisplayOptions.ReservedSeats) Or
            ((Not reserved) And (choice = DisplayOptions.VacantSeats)) Then

            If (reserved) Then
                StrReservation = "Reserved"
                strName = m_nameList(index)
            Else
                StrReservation = "Vacant"
                strName = "..........."
            End If

            strSeatInfoStrings(i) = String.Format("{0,4}  {1,-8} {2, -20} {3,10:f2}",
                                                  index + 1, StrReservation, strName, m_priceList(index))
            i += 1
        End If

    Next
    Return count

End Function

发现了错误!我忘了在InitializeGUI中调用UpdateGUI

Private Sub UpdateGUI()
    'Clear the listbox and make it ready for new data.
    ReservationList.Items.Clear()

    'size of array is determined in the callee method
    Dim seatInfoStrings As String() = Nothing
    Dim calcOption As DisplayOptions = DirectCast(cmbDisplayOptions.SelectedIndex, DisplayOptions)

    Dim count As Integer = m_seatMngr.GetSeatInfoStrings(calcOption, seatInfoStrings)

    If count > 0 Then
        ReservationList.Items.AddRange(seatInfoStrings)
    Else
        ReservationList.Items.Add("Nothing to display!")
    End If