![](/img/trans.png)
[英]How to add text item to a winform listbox that been already bound with a datasource
[英]How to update a listbox that is bound to a datasource
我有以下內容:
var listboxchoices = new Dictionary<string, string>();
listboxchoices["color"] = "green";
listBox1.DataSource = new BindingSource(listboxchoices, null);
listBox1.DisplayMember = "Value";
listBox1.ValueMember = "Key";
要將listboxchoices [“ color”]更改為“ blue”,我要做:
listboxchoices["color"] = "blue";
但是如何獲取listBox1以反映更改?
[edit]只是要添加,列表框中的列表很長,我不想重新加載整個列表。
使用ResetBindings方法從BindingSource
重新讀取所有數據,並在控件中顯示更新的數據。
例如
BindingSource bs = new BindingSource(listboxchoices, null);
listbox1.DataSource = bs;
// make changes to listboxchoices
bs.ResetBindings(false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.