簡體   English   中英

如何更新綁定到數據源的列表框

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM