0

私はリストボックス(listStorageLocations)を持っています-それはlistStorageLocationsBindingSourceと呼ばれるBindingSourceにバインドされています。このBindingSourceは、Settings.Default.StorageLocationsのStringDictionaryアイテムのコレクションにバインドされています。次に、リストボックスのデータソースがバインディングソースに設定されます。私は一生の間、このブラストされたリストボックスに何も表示することができません(特にテスト項目を追加しない限り)。

ここにいくつかのコードがあります:

フォームの初期化:

listStorageLocations.DisplayMember = "Key";
listStorageLocations.ValueMember = "Value";
listStorageLocationsBindingSource.DataSource = Settings.Default.StorageLocations;
listStorageLocations.DataSource = listStorageLocationsBindingSource;
if (Settings.Default.StorageLocations == null)
    Settings.Default.StorageLocations = new StringDictionary();

新しい保存場所を追加するためのボタンロジック:

private void btnAddStorageLocation_Click(object sender, EventArgs e)
{
    if (!txtStorageLocation.Text.Equals("") && !(txtStorageLocationName.Text.Equals("") &&
          !(StorageLocationsContainsPath(txtStorageLocation.Text)) &&
          !(StorageLocationsContainsName(txtStorageLocationName.Text))))
    {
        Settings.Default.StorageLocations.Add(txtStorageLocationName.Text, txtStorageLocation.Text);
    }
    Settings.Default.Save();

    listStorageLocationsBindingSource.ResetBindings(false);
}

私は腕を78度の角度で持ち上げ、7つの燃えるようなフープを飛び越えて、頭の上に立って無駄にしようとしました。彼らの愚かな詳細は私が欠けていますか?

また、ここでSettings.Default.Save()を呼び出して、StringDictionaryの初期値を取得しますが、もちろん、アプリを再起動するとアイテムがないため、これも機能しません。

4

1 に答える 1

0

私はそれを理解しました、StringDictionaryクラスはSerializableではないので、私の設定はSettings.Default.Save()で保存されません-それで私はこれで間違った方向に向かっています。別の方法でデータを保存します。

于 2010-05-17T22:19:56.763 に答える