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

首先设置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. unity3d Time.deltaTime个人理解

    官方的解释是:静态只读属性,时间增量,渲染上一帧所花费的时间看下面的代码 /// <summary> /// 每帧刷新 /// </summary> void Update() ...

  2. Accelerated molecular dynamics simulation of Silicon Crystals on TaihuLight using OpenACC 阅读

    基于OpenACC的太湖之光硅晶体加速分子动力学模拟    2020 摘要:以SW26010异构多核处理器和扩展的编程模型,使用多体势(Tersoff)执行固体共价晶体的分子动力学(MD)模拟. Am ...

  3. Win10家庭版安装docker desktop

    1.开启Hyper-V在桌面新建hyperv.cmd文件,内容如下: pushd "%~dp0" dir /b %SystemRoot%\servicing\Packages\*H ...

  4. SpringBoot 配置内部tomcat https双向验证

    1.在application.properties或者application.yml配置文件中加入 server: port: 8443 ssl: key-store: classpath:xxxx. ...

  5. mybatis自增主键的获取

    实体类 package org.example.entity; public class User { private Integer id; private String name; private ...

  6. vuexy full-wersion项目安装报错问题处理

    npm install grpc@1.23.3 --ignore-scripts npm rebuild node-sass

  7. UGUI获取文本的字符内容像素宽度 【转】

    在做文本框的时候,我们经常碰到需要计算字符输入的长度,然后适当地做处理.这个时候不能直接了当地拿text.Length来用,原因有: 1.字符会因为fontSize的大小不同而有不同的宽度: 2.即使 ...

  8. iOS开发之UIImage压缩处理

    IOS中UIImage的数据量压缩有两种方式,一种是图片尺寸不变,降低图片分辨率,代码方法为: //1.0为压缩系数,介于0~1之间.压缩系数越小,会大大降低图片清晰度 NSData *data = ...

  9. NifytGUI——ListBox控件

    ListBox控件的用法,创建一个xml,代码如下: <?xml version="1.0" encoding="UTF-8" standalone=&q ...

  10. 04 使用 BTrace 进行拦截调试

    BTrace BTrace 可以动态地向目标应用程序的字节码注入追踪代码,使用的技术有 JavaCompilerApi, JVMTI, Agent, Instrumentation+ASM 使用方法: ...