我正在制作一个允许用户将表格添加到列表的程序。但我无法让列表显示在 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