[英]Combobox options not changing when datasource updated
因此,当我在主窗口构造函数中使用此方法时,数据将正确加载:
public void Load_Dropdown(configuration con)
{
bindinglist = new BindingList<ListCollection.ListsList>(Get.ListCollection(con).List);
BindingSource bSource = new BindingSource {DataSource = bindinglist};
sharepointListSelect.DataSource = bSource;
sharepointListSelect.DisplayMember = "Title";
sharepointListSelect.ValueMember = "ID";
}
这样做很好,但是当我尝试在以后调用类似的方法来更新选项时,什么也没有发生,因为下拉菜单中的选项不会更改。
我调用的更新方法如下所示:
public bool Reload_Dropdown(configuration con)
{
bindinglist = new BindingList<ListCollection.ListsList>(Get.ListCollection(con).List);
BindingSource bSource = new BindingSource { DataSource = bindinglist };
sharepointListSelect.DataSource = bSource;
sharepointListSelect.DisplayMember = "Title";
sharepointListSelect.ValueMember = "ID";
//There is other logic here, but i left it out as it isn't relevant
return true;
}
顺便说一句,绑定列表对象在类中初始化为:
private BindingList<ListCollection.ListsList> bindinglist;
我知道,现在我可以重用第一种方法,但是我拆分了声明以调试为什么它首先导致更新失败。
我很愚蠢-因此问题不是这两种方法,而是我如何调用该方法。 如果它不是静态的,则不能从另一种形式调用方法。 对我而言,巨大的监督-我认为对MVC有点习惯。
只要您从同一方法中调用此解决方案,它就可以正常工作。 我选择了一个按钮,它将刷新下拉菜单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.