2010-05-17 67 views
0

我有一个列表框(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中获得一些初始值 - 但当然 - 这不起作用,因为当我重新启动应用程序 - 没有项目。

+0

没有人有这方面的经验吗? – Jack 2010-05-17 15:49:59

回答

0

嗯,我想通了,StringDictionary类isnt可串行化,所以我的设置不保存Settings.Default.Save() - 所以我在这个错误的方向。要以不同的方式存储数据。