listbox bind datasource, refresh data

来源:互联网 发布:射雕同人之悦与君知 编辑:程序博客网 时间:2024/06/08 12:16

1, set the binding source, select the datasource from system business object

this.listBox1.DataSource = this.iLicenseKeyBindingSource;this.listBox1.DisplayMember = "LicenseKey";this.listBox1.ValueMember = "LicenseKeyId";iLicenseKeyBindingSource.DataSource = Licenses;


2. set the datasource of the binding source,

     Important: it is different from normal databinding, do not set the DataSource of your BindingSource, set the DataSource of the ListBox.DataSource.

 //iLicenseKeyBindingSource.DataSource = Licenses; listBox1.DataSource = Licenses;     // Licenses is a list of your business object

 

3.  change the list,  refresh the listbox

Licenses.Add(new LicenseKey());((CurrencyManager)listBox1.BindingContext[Licenses]).Refresh();


 

原创粉丝点击