BandingList 泛型集合数据绑定


  public IList IStudent = new List(); 
  public BindingList BStudent = new BindingList();

  ///


  /// 加载数据返回IList
  ///

  IList BindDataList(DataTable dt)
  {
    IStudent.Clear();
    foreach (DataRow row in dt.Rows)
    {
      Student student = new Student();
      student.Name = row["name"].ToString();
      student.Sex = row["sex"].ToString();
      IStudent.Add(student);
    }
    IStudent.Add(new Student() { Name = "2", Sex = "3" });
    return IStudent;
  }

  ///


  /// 绑定数据
  ///

  public void Loading()
  {
    BStudent = new BindingList(BindDataList(dt));
    gridControl1.DataSource = BStudent;
  }

  ///


  /// 实体类
  ///

  public class Student
  {
    public string Name { get; set; }

    public string Sex { get; set; }
  }

Net