zoukankan      html  css  js  c++  java
  • 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排序实现

  • 相关阅读:
    window.print()分页打印
    获取输入框中光标位置
    JavaScript数据结构与算法描述-队列
    .NET中获取IP地址
    记录一次排查C#使用UI Automation获取程序元素的bug
    虚拟机为win server 2012 添加新磁盘
    为halo博客添加ssl证书(配合nginx反向代理)
    初学nginx反向代理
    公告时间轴
    hackthebox-Archetype
  • 原文地址:https://www.cnblogs.com/iack/p/3587101.html
Copyright © 2011-2022 走看看