我有两个列表和一个列表框,这些列表都是它们自己的类,列表框位于 Form1 上。每个列表都由一个 GUI 添加到各自的名称中,FrmPickups 用于拾取列表,FrmVisits 用于列表。
我的问题是,当我将数据添加到列表时,如何将其存储到数据库中以便在项目启动时重新加载,以及如何在启动时将其加载到列表框中。
部分代码如下:
数据添加到列表中,如下所示:
theVisit.name = txtName.Text;
theVisit.address = txtAddress.Text;
theVisit.arrival = DateTime.Parse(txtArrival.Text);
theVisit.Lat = Double.Parse(txtLat.Text);
theVisit.Lon1 = Double.Parse(txtLong.Text);
theVisit.type = "Visit";
ListBox 内容添加在下面
/*
* Update the list on this form the reflect the visits in the list
*/
lstVisits.Items.Clear();
//Clear all the existing visits from the list
List<String> listOfVis = theList.listVisits();
//Get a list of strings to display in the list box
List<String> listOfpic = thePickup.listPickups();
//Get a list of strings to display in the list box
lstVisits.Items.AddRange(listOfVis.ToArray());
//Add the strings to the listBox. Note to add a list of strings in one go we have to
//use AddRange and we have to use the ToArray() method of the list that we are adding
lstVisits.Items.AddRange(listOfpic.ToArray());
//Add the strings to the listBox. Note to add a list of strings in one go we have to
//use AddRange and we have to use the ToArray() method of the list that we are adding