/// <summary>
/// 排序顺序
/// </summary>
bool asc;
/// <summary> /// Dgv点击排序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgv_Jobs_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { int index = e.ColumnIndex; if (asc) { switch (index) { case 1: listStaffs = listStaffs.OrderByDescending(w => w.Age).ToList(); break; case 3: listStaffs = listStaffs.OrderByDescending(w => w.Wage).ToList(); break; case 4: listStaffs = listStaffs.OrderByDescending(w => w.MainAblity).ToList(); break; case 5: listStaffs = listStaffs.OrderByDescending(w => w.AssistantAbility).ToList(); break; case 6: listStaffs = listStaffs.OrderByDescending(w => w.LearningAbility).ToList(); break; case 7: listStaffs = listStaffs.OrderByDescending(w => w.Greed).ToList(); break; case 8: listStaffs = listStaffs.OrderByDescending(w => w.Attitude).ToList(); break; } asc = false; } else { switch (index) { case 1: listStaffs = listStaffs.OrderBy(w => w.Age).ToList(); break; case 3: listStaffs = listStaffs.OrderBy(w => w.Wage).ToList(); break; case 4: listStaffs = listStaffs.OrderBy(w => w.MainAblity).ToList(); break; case 5: listStaffs = listStaffs.OrderBy(w => w.AssistantAbility).ToList(); break; case 6: listStaffs = listStaffs.OrderBy(w => w.LearningAbility).ToList(); break; case 7: listStaffs = listStaffs.OrderBy(w => w.Greed).ToList(); break; case 8: listStaffs = listStaffs.OrderBy(w => w.Attitude).ToList(); break; } asc = true; } dgv_Jobs.DataSource = listStaffs; }
可以通过对datasource排序实现