0

2 つのリストと 1 つのリスト ボックスがあります。リストはそれぞれ独自のクラスであり、リスト ボックスは Form1 にあります。各リストは、ピックアップ リストの場合は FrmPickups、リストの場合は FrmVisits というそれぞれの名前を持つ GUI によって追加されます。

私の質問は、データをリストに追加するときに、プロジェクトの起動時に再ロードされるようにデータベースに保存する方法と、起動時にリスト ボックスにロードする方法です。

一部のコードは次のとおりです。

データは次のようにリストに追加されます。

        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
4

1 に答える 1

0

ほとんどのプログラミングの問題と同様に、これを行うには無数の方法があります。データベースの設計を制御できる場合は、リストを格納する BLOB 列またはイメージ列を用意することを検討してください。C# のシリアル化を利用して、生のバイトをその列に詰め込むことができます。これにより、SQL クエリの観点からリストの詳細をクエリすることができなくなります。起動時の読み込みに関しては、列から生のバイトを取得し、逆シリアル化し、フォームのコントロールにアタッチします。

于 2012-12-05T13:11:40.300 に答える