我们经常遇到这样的问题,字符串尾部带数字,如何正确排序;

首先设置GridView ,Columns 的相关列,设置属性中,SortMode为Custom

解决思路,把字符串尾缀数字,分离出来。先比较去除尾部数字的字符串,再比较尾部数字位。

gridView.CustomColumnSort += GridView_CustomColumnSort;

private void GridView_CustomColumnSort(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnSortEventArgs e)
{
if (e.Column == gridColumn)
{
string value1 = e.Value1.ToString();
string value2 = e.Value2.ToString();
var cc1 = GetNumberIndex(value1);
var cc2 = GetNumberIndex(value2);
if (cc1 > -1 && cc2 > -1)
{
string zm1 = value1.Substring(0, cc1);
string zm2 = value2.Substring(0, cc2);
if (zm1 == zm2)
{
string nb1 = value1.Substring(cc1);
string nb2 = value2.Substring(cc2);
decimal.TryParse(nb1, out decimal dec1);
decimal.TryParse(nb2, out decimal dec2);
int result = Comparer<decimal>.Default.Compare
(dec1, dec2);
e.Result = result;
e.Handled = true;
}
}
}
} private int GetNumberIndex(string value)
{
int v = -1;
if (value != null && value.Length > 1)
{
int i = 0;
for (; i < value.Length; i++)
{
if (char.IsNumber(value[i]))
{
if (i != 0)
{
v = i;
}
break;
}
}
}
return v;
}

C# DevExpress gridview 字符串尾部带数字如何排序的更多相关文章

  1. mysql—从字符串中提取数字(类型1)

    select reason,CHAR_LENGTH(reason),mid(reason,5,CHAR_LENGTH(reason)-5)+0 from `table` 解释: CHAR_LENGTH ...

  2. delphi 简单的删除字符串尾部数字的代码

    delphi  简单的删除字符串尾部数字的代码 方式一: function FilterShowName(const sName: String): String; var I: Integer; b ...

  3. 写出将字符串中的数字转换为整型的方法,如:“as31d2v”->312,并写出相应的单元测试,正则去掉非数值、小数点及正负号外的字符串

    写出将字符串中的数字转换为整型的方法,如:"as31d2v"->312,并写出相应的单元测试,输入超过int范围时提示不合法输入. public struct Convert ...

  4. 字符串--java中判断字符串是否为数字的方法的几种方法?

    ava中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < ...

  5. C#验证字符串是否是数字,是否包括中文,是否是邮箱格式,是否是电话格式

    using System;     using System.Web;     using System.Text;     using System.Web.UI.WebControls;     ...

  6. java中判断字符串是否为数字的方法的几种方法

    1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ ...

  7. 关于怎样获取DevExpress GridView过滤后或排序后的数据集问题(转)

    GridView用自带的过滤功能过滤数据后,想要获取过滤后的数据集,有两种方式: 一.笨办法就是循环遍历GridView,根据gridView.GetRow()或者gridView.GetDataRo ...

  8. DevExpress GridView 整理(转)

    DevExpress GridView 那些事儿 1:去除 GridView 头上的 "Drag a column header here to group by that column&q ...

  9. DevExpress GridView 那些事儿

    1:去除 GridView 头上的 "Drag a column header here to group by that column" -->  点击 Run Desig ...

  10. DevExpress GridView 整理

    1:去除 GridView 头上的 "Drag a column header here to group by that column" -->  点击 Run Desig ...

随机推荐

  1. SVNKit使用相关工具类

    SVNKit操作SVN仓库 导入依赖 <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifa ...

  2. import cv2时出现ImportError: DLL load fail:找不到指定模块

  3. go web编程学习记录

    学习 https://segmentfault.com/a/1190000013297625的记录 简单demo package main import "github.com/gin-go ...

  4. taobao.tbk.sc.newuser.order.get( 淘宝客-服务商-新用户订单明细查询 )

    淘宝客订单表结构设计(mysql) CREATE TABLE `tbk_order` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `member_id` bi ...

  5. postgresql 之修改psql log信息级别

    1.修改当前使用的postgresql.conf文件vim /var/lib/pgsql/10/data/postgresql.conf 2.vim 下使用\notice 找到待修改项 client_ ...

  6. nodejs 程序打包 打包 koa express 项目 源代码保护加密

    打包项目 几个可以 把 nodejs 打包成单个文件的库,为了方便或保护源代码,都可以尝试,打包完成需要测试,如果项目有特殊依赖,可能会失败. https://github.com/nexe/nexe ...

  7. Python Cli 编写指南

    Python Cli 编写指南 python实现cli 环境: python 3.8 库 python自带argparse 指南 简单示例 : cli.py import argparse def c ...

  8. Jmeter 5.0 遇见connection reset问题

    问题:大并发时遇见java.net.SocketException: Connection reset 测试过程中经常遇见connection reset ,原因是大数据量发送时,服务器不能接纳那么多 ...

  9. TypeScript - 安装,类型

    // 要使用typescript需要全局安装 通过tsc -v 来验证是否安装成功 npm i -g typescript// ts 文件中完全可以写js语法, 完全兼容js // ts 本身在运行时 ...

  10. 「NOTE」常系数齐次线性递推

    要不是考到了,我还没发现这玩意我不是很会-- # 前置 多项式取模: 矩阵快速幂. # 常系数齐次线性递推 描述的是这么一个问题,给定数列 \(c_1,c_2,\dots,c_k\) 以及数列 \(f ...