私はリストボックス(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の初期値を取得しますが、もちろん、アプリを再起動するとアイテムがないため、これも機能しません。