1

ユーザーがリストにテーブルを追加できるようにするプログラムを作成しています。しかし、リストをlistBoxに表示するのに問題があります

テーブルとそのプロパティは、クラスの元のリストに問題なく追加されますが、表示しようとすると、データがなくなったようです。リストに何か問題があると思いますが、何が原因かわかりません。リストを別の配列リストに入れてみましたが、結果はありません。

Imports Table_Tracker_Library
Public Class Main_Form
    Private Property _Table As New Table
    Private Property _ShowList As Table()

Private Sub Btn_Add_Table_Click(sender As Object, e As EventArgs) Handles Btn_Add_Table.Click
    Form_Create_Button.Show()
End Sub



Public Sub Renew()
    _ShowList = _Table.GetList()
    Me.LB_ActiveTables.ClearSelected()
    For Each table As Table In _ShowList
        LB_ActiveTables.Items.Add("Table #" & table.Number)
    Next
    LB_ActiveTables.Refresh()
End Sub

'Private Function GetList() As Table()
'    Dim TempList As New List(Of Table)
'    For Each table As Table In _Table.ListOfTable
'        TempList.Add(table)
'    Next
'    Return TempList.ToArray
'End Function
End Class

-

Imports Table_Tracker_Library
Public Class Form_Create_Button
    Private Property _Table As New Table

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_addtable.Click
        _Table.CreateTable(Me.txb_TableNr.Text, Me.txb_PplNr.Text)
        Main_Form.Renew()
        Me.Close()
    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btn_discard.Click
        Me.Close()
        End Sub
End Class

-

Public Class Table
    Public Property Number As Int32
    Public Property NumberOfPeople As Int32
    Public Property ListOfTable As New List(Of Table)



    Public Sub CreateTable(TableNrString As String, PersonNrString As String)
        Dim TableNR As Int32 = CInt(TableNrString)
        Dim PersonNr As Int32 = CInt(PersonNrString)
        Dim NewTable As New Table With {.Number = TableNR, .NumberOfPeople = PersonNr}
        AddTable(NewTable)
    End Sub

    Private Sub AddTable(Table As Table)
        ListOfTable.Add(Table)
    End Sub

    Public Function GetList() As Table()
        Dim TempList As New List(Of Table)
        For Each table As Table In ListOfTable
            TempList.Add(table)
        Next
        Return TempList.ToArray
    End Function

End Class
4

1 に答える 1

1

プライマリ フォームの を にprivate変更しましたpublic

Public Class Main_Form
    Public Property Table As New Table
    Private Property _ShowList As Table()

.....

セカンダリフォームでメインフォームのテーブルプロパティを使用しました

Public Class Form_Create_Button


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_addtable.Click
        If IsNumeric(txb_TableNr.Text) = True AndAlso IsNumeric(txb_PplNr.Text) Then
            If Main_Form.Table.TableIsAvailable(txb_TableNr.Text, txb_PplNr.Text) = True Then
                Main_Form.Table.CreateTable(Me.txb_TableNr.Text, Me.txb_PplNr.Text)
                Main_Form.RenewListBox()
                Me.Close()
            Else
                MessageBox.Show("Table already taken!", "Invalid Table", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
            End If
        Else
            MessageBox.Show("Invalid table number or amount of people", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
        End If
    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btn_discard.Click
        Me.Close()
    End Sub



End Class
于 2013-10-25T15:48:05.927 に答える