泛型List<T>作为DataGriView数据源
2012-03-29 11:20
417 查看
类Student:
对控件DataGridView1绑定:
如果通过TextBox 输入来查询:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace STUDENT { class Student { int id; public int Id { get { return id; } set { id = value; } } string name; public string Name { get { return name; } set { name = value; } } int age; public int Age { get { return age; } set { age = value; } } string sex; public string Sex { get { return sex; } set { sex = value; } } public Student(int id, string name, int age, string sex) { this.Id = id; this.Name = name; this.Age = age; this.Sex = sex; } } }
对控件DataGridView1绑定:
List<Student> li=new List<Student>(); Student st1=new Student(1,"张三",20,"男"); li.Add(st1); dataGridView1.DataSource=li;
如果通过TextBox 输入来查询:
List<Student> li = new List<Student>(); Student st1 = new Student(1, "张三", 20, "男"); Student st2 = new Student(2, "李四", 21, "男"); Student st3 = new Student(3, "王五", 22, "男"); Student st4 = new Student(4, "小红", 21, "女"); li.Add(st1); li.Add(st2); li.Add(st3); li.Add(st4); List<Student> li1 = new List<Student>(); foreach (Student item in li) { if (item.Name.Contains(TextBox.Text.Trim())) { li1.Add(item); } } dataGridView1.DataSource = li1;
相关文章推荐
- C#中string[]数组和list<string>泛型的相互转换
- DataSet和List<T> 泛型之间互相转换
- 将DataTable转换成List<T>泛型集合助手类
- 在Silverlight中使用List<Object>构造交叉表作为Silverlight的DataGrid的数据源
- <转>用已经存在的xml文件作为flex柱状图饼状图等数据源的方式有几种?
- C# 泛型List<T>学习总结
- 程序员学习之路一 泛型列表List<T>基本用法
- GridControl 控件-----List<T>数据源 实现主从表关系绑定
- JAVA POI Excel导出,数据源可以是List<Map>或者List<Model>类型
- C# List<T> 泛型的反射, 泛型 函数的反射
- C#中泛型集合List<T>反序列化问题及解决方法
- 泛型与反射机制处理ComBox绑定的数据源是List<实体对象>
- list<T>作为datagridview的datasource
- C#中string[]数组和list<string>泛型的相互转换
- C#基础精华03(常用类库StringBuilder,List<T>泛型集合,Dictionary<K , V> 键值对集合,装箱拆箱)
- ArrayList<Integer> list = new ArrayList<Integer>(); 在这个泛型为Integer的ArrayList中存放一个String类型的对象。
- Gridview 绑定泛型List<T> 排序方法
- Winform中DataGridView绑定List<T>数据源时,点击DataGridView列头不能自动排序解决方法
- C#读取数据库返回泛型集合 把DataSet类型转换为List<T>泛型集合
- ArrayList<Integer> list = new ArrayList<Integer>();在这个泛型为 Integer 的 ArrayList 中存放一个 String 类型的对象。