C++BuilderXE 如何让listView按文件名数字排序而非字母排序

int m_nDataColSort=0;

bool IsAsc=true;

void __fastcall TForm1::RzListView4Compare(TObject *Sender, TListItem *Item1, TListItem *Item2,
int Data, int &Compare)
{
if(m_nDataColSort==0)
{

//按列表第二列排序
//Compare=CompareText(Item1->SubItems->Strings[0] ,Item2->SubItems->Strings[0] );
//按列表第一列排序

Compare=CompareText(Item1->Caption ,Item2->Caption );
}
}

//导入文件夹

void __fastcall TForm1::BitBtn29Click(TObject *Sender)

{

AnsiString Dir = "";

AnsiString CGstr;

if (!FolderDialog1->Execute()) return;

Dir =FolderDialog1->Directory;

//

int Trnum=0;

TSearchRec sr;

int iAttributes=0x0000003F;

int Oldlist;

if(FindFirst(Dir+"\\*.*",faDirectory,sr) == 0)

{

Oldlist = RzListView4->Items->Count;

do

{

if( !sr.Name.Pos(".") ) //sr.Name!="." && sr.Name!=".."

{

TListItem *pItem=0;

pItem=RzListView4->Items->Add();

//列表第一列,取出文件夹名进行格式化成字母格式"000"

if( sr.Name.Length()==1)
pItem->Caption="00"+sr.Name;
else if( sr.Name.Length()==2)
pItem->Caption="0"+sr.Name;
else
pItem->Caption=sr.Name; //AnsiString().sprintf("%03d",Oldlist+1); // ;

pItem->SubItems->Add(Dir+"\\"+sr.Name);

//pItem->SubItems->Add("***");

// if(CheckBox26->Checked)

// pItem->SubItems->Add(RightStr(AnsiString(sr.Name),3));

// else

// pItem->SubItems->Add("***");

//

// Ttree->Add(Dir+"\\"+sr.Name);

//Trnum+=1;

Oldlist++;

}

} while(FindNext(sr) == 0);

FindClose(sr);

}

//文件夹名排序
m_nDataColSort=0;
IsAsc=false;
RzListView4->AlphaSort();

RzListView4->Column[0]->Caption="序号[ 共"+AnsiString(Oldlist)+" ]" ;

}

相关推荐
二哈赛车手5 小时前
新人笔记---ApiFox的一些常见使用出错
java·笔记·spring
吃好睡好便好6 小时前
在Matlab中绘制横直方图
开发语言·学习·算法·matlab
栗子~~6 小时前
JAVA - 二层缓存设计(本地缓冲+redis缓冲+广播所有本地缓冲失效) demo
java·redis·缓存
YDS8296 小时前
DeepSeek RAG&MCP + Agent智能体项目 —— RAG知识库的搭建和接口实现
java·ai·springboot·agent·rag·deepseek
仰泳之鹅6 小时前
【C语言】自定义数据类型2——联合体与枚举
c语言·开发语言·算法
未若君雅裁7 小时前
MyBatis 一级缓存、二级缓存与清理机制
java·缓存·mybatis
于小猿Sup7 小时前
VMware在Ubuntu22.04驱动Livox Mid360s
linux·c++·嵌入式硬件·自动驾驶
AI人工智能+电脑小能手8 小时前
【大白话说Java面试题 第65题】【JVM篇】第25题:谈谈对 OOM 的认识
java·开发语言·jvm
阿维的博客日记8 小时前
Nacos 为什么能让配置动态生效?(涉及 @RefreshScope 注解)
java·spring
雨辰AI8 小时前
SpringBoot3 + 人大金仓读写分离 + 分库分表 + 集群高可用 全栈实战
java·数据库·mysql·政务