我有一個列表框(listStorageLocations) - 這綁定到一個名爲listStorageLocationsBindingSource的BindingSource。此BindingSource綁定到我的Settings.Default.StorageLocations中的StringDictionary項目的集合。列表框的數據源然後被設置爲綁定源。我不能爲我的生活得到任何東西顯示在這個爆炸的列表框中(除非我專門添加測試項目)。列表框綁定到Specialized.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中獲得一些初始值 - 但當然 - 這不起作用,因爲當我重新啓動應用程序 - 沒有項目。
沒有人有這方面的經驗嗎? – Jack 2010-05-17 15:49:59