【问题标题】:listbox bound to a Specialized.StringDictionary does not update绑定到 Specialized.StringDictionary 的列表框不会更新
【发布时间】:2010-05-17 04:09:48
【问题描述】:

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

【问题讨论】:

  • 没人有这方面的经验吗?

标签: c# listbox application-settings stringdictionary


【解决方案1】:

好吧,我想通了,StringDictionary 类不是可序列化的,所以我的设置没有用 Settings.Default.Save() 保存 - 所以我走错了方向。以不同的方式存储数据。

【讨论】:

    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 2011-07-14
    • 1970-01-01
    • 2014-08-26
    • 1970-01-01
    • 2015-09-02
    相关资源
    最近更新 更多