using System; using System.ComponentModel; using System.Data; using System.Windows.Forms; namespace DataGridViewSort { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: 这行代码将数据加载到表“companyDataSet.clerk”中。您可以根据需要移动或删除它。 this.clerkTableAdapter.Fill(this.companyDataSet.clerk); } //通过表格列排序实现 private void button1_Click(object sender, EventArgs e) { this.dataGridView1.Sort(dataGridView1.Columns[3],ListSortDirection.Ascending); } //通过更改数据源实现筛选 private void button2_Click(object sender, EventArgs e) { DataView dv = new DataView(this.companyDataSet.clerk, "department='研发部'", "age Asc", DataViewRowState.CurrentRows); dataGridView1.DataSource = dv; } } }
备注:在dataview对象中筛选不需要加“N”