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

首先设置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. Windows支持多个远程连接

    1.点击 开始-->运行-->输入"gpedit.msc",进入本地组策略编辑器 2.点击 计算机配置-->管理模板-->Windows组件-->远程 ...

  2. 执行celery --version报错

    python 3.7.4安装celery后执行celery --version报错 安装命令: pip install celery -i https://pypi.douban.com/simple ...

  3. prometheus Alertmanager webhook

      一.自定义邮件告警 二.使用docker部署微信机器人告警 1.制作镜像 2.启动容器和指定webhook容器 一.自定义邮件告警 在alertmanager服务的配置文件中指定自定义告警文件 # ...

  4. Java lombok包中的常用注解,便捷化开发POJO类

    lombok包中的一些常用注解 如何使用Lombok?Lombok提供注解方式来提高代码的简洁性,常用注解有:    @Data    @Setter @Getter    @NonNull    @ ...

  5. jQuary学习(一)

    一.jQuary简介 jQuery是继prototype之后又一个优秀的Javascript框架.其宗旨是--WRITE LESS,DO MORE,写更少的代码,做更多的事情. jQuery能够使用户 ...

  6. 整合mybatis-示例

    引入依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.o ...

  7. this.$refs 获取的值是undefined

    以下是父组件内的代码截图 如果想取子组件内的方法,参数,等可以试以下两种方法 1.在mounted内使用this.$nextTick(()=>{   }) 2.直接再undated() {} 内 ...

  8. vue3 生成二维码 qrcodejs2-fix

    1.安装qrcodejs2-fix npm install qrcodejs2-fix 2.引入qrcodejs2-fix import QRCode from 'qrcodejs2-fix'; 3. ...

  9. Ant Design 分页数据回显问题

    我们可以创建一个新的值来保存这些数据allSingleSelectedRowKeys: 下面是我们的HTML结构 <a-table :row-selection="{ selected ...

  10. Mac电脑设置环境变量

    转载自:https://jingyan.baidu.com/article/8065f87f47b29523312498e4.html 1.使用快捷键Command+R(或者Windows键+R),或 ...