Winform Datagridview 点击headercolumn排序

Winform Datagridview 点击headercolumn排序
        

/// <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; }
Winform Datagridview 点击headercolumn排序

可以通过对datasource排序实现

Winform Datagridview 点击headercolumn排序,布布扣,bubuko.com

Winform Datagridview 点击headercolumn排序

上一篇:Win2008如何安装iis Windows2008安装iis方法图文教程


下一篇:Windows Phone开发(34):路径标记语法