2014-10-29 68 views
0

尝试绑定列表框c BindingSource。绑定列表框seletedltems

有这样一个实体

// Entitys 
public class Sp 
{ 
    public int Id { get; set; } 
    public int? IdTemp { get; set; } //Foreing Key 
    public Temp Temp { get; set; } 
    public string Name { get; set; } 
} 
public class Temp 
{ 
    public int Id { get; set; } 
    public string Caption { get; set; } 
    public ICollection<Sp> Sps { get; set; } 
} 

创建的BindingSource

var b = new BindingSource{ DataSource = new BindingList<Temp>().ToList() }; 

创建结合

listBox1.SelectionMode = SelectionMode.MultiSimple; 
//Throws an error: 'SelectedItems' because it is read-only 
listBox1.DataBindings.Add("SelectedItems", B, "Sps.IdTemp", true); 

回答

0

检查如何使用DataSourceDataBindings正确这样的回答: How to add new item into listbox that using datasource?

将任何东西绑定到ListBoxSelectedItems属性是没有意义的。 相反,您可以将DataSource中的某些内容与Text属性或类似内容绑定。