1、datagridview 日期列排序
private void Form1_Load(object sender, EventArgs e) { //方法1 dataGridView1.ColumnHeaderMouseClick += tempView_ColumnHeaderMouseClick; DataTable dt = Create(); dataGridView1.DataSource = dt; //方法2 dataGridView2.SortCompare += dataGridView2_SortCompare; fillDatagridview(dataGridView2, dt); } #region 方法1,已知那一列是日期类型,以datasourcr方式绑定数据 //创建表,为了culture的原因,日期列的数据源类型是字符串而不是日期类型 public DataTable Create() { DataTable dt = new DataTable(); try { dt.Columns.Add("name"); dt.Columns.Add("birthdate"); dt.Rows.Add("m", "04.01.1969"); dt.Rows.Add("n", "05.12.1961"); dt.Rows.Add("n", "06.04.1963"); } catch (Exception) { throw; } return dt; }