• 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; }

    可以通过对datasource排序实现

  • 相关阅读:
    poj 3468 A Simple Problem with Integers
    Autolayout约束动画化-Animating Autolayout Constraints
    HDU 1325 POJ 1308 Is It A Tree? (并查集)
    java小游戏代码
    《大话操作系统——做坚实的project实践派》(5)
    关于mysql存储过程创建动态表名及參数处理
    LeetCode Remove Duplicates from Sorted Array II
    centos 7安装 navicat
    Zxing二维码扫描
    Android adb shell学习心得(四)
  • 原文地址:https://www.cnblogs.com/iack/p/3587101.html
Copyright © 2020-2023  润新知