码迷,mamicode.com
首页 > 其他好文 > 详细

BandingList 泛型集合数据绑定

时间:2019-09-29 15:41:03      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:tostring   集合   ble   tar   load   reac   class   add   数据   

  public IList<Student> IStudent = new List<Student>(); 
  public BindingList<Student> BStudent = new BindingList<Student>();

  /// <summary>
  /// 加载数据返回IList
  /// </summary>

  IList<Student> 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;
  }

  /// <summary>
  /// 绑定数据
  /// </summary>

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

  /// <summary>
  /// 实体类
  /// </summary>

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

    public string Sex { get; set; }
  }

 

BandingList 泛型集合数据绑定

标签:tostring   集合   ble   tar   load   reac   class   add   数据   

原文地址:https://www.cnblogs.com/Csharp-Soul/p/11608137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!