delphi7 stringgrid 点列头排序
最近在做stringgrid的项目, 下面delphi7 正常使用,均摘抄网路,但做过细微调整才能正常使用
首先排序的过程
procedure Quicksort(Grid: TStringGrid; var List: array of integer; min, max, sortcol, datatype: Integer);
{List is a list of rownumbers in the grid being sorted}
var
med_value: integer;
hi, lo, i: Integer;
function compare(val1, val2: string): integer;
var
int1, int2: integer;
float1, float2: extended;
errcode: integer;
begin
case datatype of
0:
result := ANSIComparetext(val1, val2);
1:
begin
int1 := strtointdef(val1, 0);
int2 := strtointdef(val2, 0);
if int1 > int2 then
result := 1
else if int1 < int2 then
result := -1
else
result := 0;
end;
2:
begin
val(val1, float1, errcode);
if errcode <> 0 then
float1 := 0;
val(val2, float2, errcode);
if errcode <> 0 then
float2 := 0;
if float1 > float2 then
result := 1
else if float1 < float2 then
result := -1
else
result := 0;
end;
else
result := 0;
end;
end;
begin
{If the list has <= 1 element, it's sorted}
if (min >= max) then
Exit;
{Pick a dividing item randomly}
i := min + Trunc(Random(max - min + 1));
med_value := List[i];
List[i] := List[min]; { Swap it to the front so we can find it easily}
{Move the items smaller than this into the left
half of the list. Move the others into the right}
lo := min;
hi := max;
while (True) do
begin
// Look down from hi for a value < med_value.
while compare(Grid.cells[sortcol, List[hi]], grid.cells[sortcol, med_value]) >= 0 do
(*ANSIComparetext(Grid.cells[sortcol,List[hi]]
,grid.cells[sortcol,med_value])>=0 do*)
begin
hi := hi - 1;
if (hi <= lo) then
Break;
end;
if (hi <= lo) then
begin {We're done separating the items}
List[lo] := med_value;
Break;
end;
// Swap the lo and hi values.
List[lo] := List[hi];
inc(lo); {Look up from lo for a value >= med_value}
while Compare(grid.cells[sortcol, List[lo]], grid.cells[sortcol, med_value]) < 0 do
begin
inc(lo);
if (lo >= hi) then
break;
end;
if (lo >= hi) then
begin {We're done separating the items}
lo := hi;
List[hi] := med_value;
break;
end;
List[hi] := List[lo];
end;
{Sort the two sublists}
Quicksort(Grid, List, min, lo - 1, sortcol, datatype);
Quicksort(Grid, List, lo + 1, max, sortcol, datatype);
end;
//datatype 0:按字符排序 1:按整型排序 2:按浮点型排序
procedure Tfrmbase.Sortgrid(var Grid : TStringGrid; sortcol,datatype:integer);
var
i : integer;
tempgrid:tstringGrid;
list:array of integer;
begin
screen.cursor:=crhourglass;
tempgrid:=TStringgrid.create(nil);
with tempgrid do
begin
rowcount:=grid.rowcount;
colcount:=grid.colcount;
fixedrows:=grid.fixedrows;
end;
setlength(list,Grid.rowcount-Grid.fixedrows);
for i:= Grid.fixedrows to Grid.rowcount-1 do
begin
list[i-Grid.fixedrows]:=i;
tempgrid.rows[i].AddStrings(grid.rows[i]);
end;
quicksort(Grid, list,0,Grid.rowcount-Grid.fixedrows-1,sortcol,datatype);
for i:=0 to Grid.rowcount-Grid.fixedrows-1 do
begin
Grid.rows[i+Grid.fixedrows].Text := '';
Grid.rows[i+Grid.fixedrows].AddStrings(tempgrid.rows[list[i]]);
end;
Grid.row:=Grid.fixedrows;
tempgrid.free;
setlength(list,0);
screen.cursor:=crdefault;
end;
列头排序
procedure Tfrmtranstat.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
c: integer;
w: integer;
Grid: TStringGrid;
begin //单击排序
Grid := Sender as TStringGrid;
with Grid do
if y <= rowheights[0] then
begin
c := 0;
w := colwidths[0];
while (c < colcount) and (w <= x) do
begin
inc(c);
w := w + colwidths[c] + gridlinewidth;
end;
sortgrid(Grid, c, 0);
end;
end;
http://blog.csdn.net/y281252548/article/details/52527807
delphi7 stringgrid 点列头排序的更多相关文章
- easyui datagrid 点击列表头排序出现错乱的原因
之前我的导师,也就是带我的同事,使用datagrid,发现点击列表头排序出现乱序,按理说只有顺序和逆序两种排序结果.因为他比较忙,当时没解决,把排序禁掉了,后来又要求一定要排序,所以他交给我. 一开始 ...
- [WPF]ListView点击列头排序功能实现
[转] [WPF]ListView点击列头排序功能实现 这是一个非常常见的功能,要求也很简单,在Column Header上显示一个小三角表示表示现在是在哪个Header上的正序还是倒序就可以了. ...
- Delphi7中ClientDataSet的排序
http://eteda.iteye.com/blog/1141312 Delphi7中ClientDataSet的排序 博客分类: Delphi 1.控件ClientDataSet的属性Inde ...
- MFC listcontrol 分列 添加行数据 点击列头排序
适用于 对话框程序 1.在工具箱中拖出 ListControl,然后右键-属性,view-Report 让你的ListControl变成这幅模样! 2.添加ListControl控件的control类 ...
- 交叉报表列头排序时遇到的oracle问题—oracle ORA-12704:字符集不匹配、varchar2转化为nvarchar2字符缺失、case when else后的字符类型要一致
在做交叉报表列头的排序时,遇到这三个问题,下面具体来说一下. 设计的数据库的表结构如图1所示: 图1 要处出来student_name_,s.grade_,s.subject_name_,这三个属性, ...
- C++ 简单实现MFC ListControl 点击列头排序
说明: SetItemData可以为每一行绑定一个DWORD类型的变量.用GetItemData可以获得这个变量.举个例子,假设CListCtrl中你需要显示某个数据表中的记录,该表有个流水号主键ID ...
- MFC CListControl 点击列头排序的实现
SetItemData可以为每一行绑定一个DWORD类型的变量.用GetItemData可以获得这个变量.举个例子,假设CListCtrl中你需要显示某个数据表中的记录,该表有个流水号主键ID,一般这 ...
- DataWindow.NET 控件 实现点击列头排序
1.定义字段 Boolean ib_SetSort = true; string is_SortType = " ...
- 点击Listview列头排序
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader) ListView1.Sorted = ...
随机推荐
- Oracle数据库零散知识05 -- 表创建,修改
1.表的创建 Create table student02(sno number); 2.表的删除 Drop table student02; 3.表的重命名 Rename student02 to ...
- java基本数据类型练习
package javafirst;//包名 public class JavaFirstDay { //基本数据类型的练习 public static void main(String[] args ...
- Cordova app 检查更新 ----创建项目、添加插件、修改插件(一)
原文:Cordova app 检查更新 ----创建项目.添加插件.修改插件(一) 使用Cordova 进行跨平台应用程序的开发 1.创建Cordova项目 $ cordova create hell ...
- Configure Two DataSources ---
67. Data Access 67.1 Configure a DataSource To override the default settings just define a @Bean of ...
- Spring Cloud和Docker搭建微服务平台
用Spring Cloud和Docker搭建微服务平台 This blog series will introduce you to some of the foundational concepts ...
- 设置npm淘宝镜像
npm config set registry https://registry.npm.taobao.org
- MySQL于ON DUPLICATE KEY UPDATE采用
今天我们做的推断插入用途MySQL于ON DUPLICATE KEY UPDATE.现在,Mark下面! 假设你想做的事,再有就是在数据库中插入数据没有数据.如果有数据更新数据,然后你可以选择ON D ...
- 我眼中的robot framework
由于近期公司需要,需要一个测试框架对于公司的服务做自动化测试. 由于服务的复杂性,人工测试的方式越来越复杂,体现在以下方面: 1.人工测试步骤复杂,容易出错.服务的复杂性会使人工测试的准备工作,测试条 ...
- C#中的字符串——用Stringbuilder类很重要
注:这篇文章基本是<C#高级编程>(第七版)第九章的学习笔记. 众所周知,C#中处理字符串通常用的都是string,它其实是.NET基础类System.String类的映射.注意一个是小写 ...
- C#中的DataGridView
关键字:C# DataGridView作者:peterzb来源:http://www.cnblogs.com/peterzb 1.DataGridView实现课程表 testcontrol.rar 2 ...