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);