0
我有兩個列表和一個列表框,這些列表都是他們自己的類,並且列表框位於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";
列表框的內容在下面
/*
* 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
你的數據訪問層是什麼樣的? –
@ DanielA.White我甚至不知道那是什麼...,這是我申請大學一年級的唯一原因,但是,我是一個總noobie – TAM
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –