61阅读

鼠标自动点击-DBGrid及ListView点击标题栏自动排序

发布时间:2017-09-08 所属栏目:qq自由幻想图标点亮

一 : DBGrid及ListView点击标题栏自动排序

一、DBGrid点击标题栏自动排序

1、建立私有变量,控制排序方向与排序字段

private

FSort, FSortField: String; //控制Grid排序

2、在titleClick中写排序代码

procedure TfrmuZhutiZhiBiaoDataInput.DBGridEhInputTitleClick(

Column: TColumnEh);

var

iFieldCount:Integer;

begin

//进行点击Title排序

for iFieldCount := 0 to DBGridEhInput.Columns.Count - 1 do

begin

if (Copy(DBGridEhInput.Columns[iFieldCount].Title.Caption,Length(DBGridEhInput.Columns[iFieldCount].Title.Caption)-1,2) = '▼') or (Copy(DBGridEhInput.Columns[iFieldCount].Title.Caption,Length(DBGridEhInput.Columns[iFieldCount].Title.Caption)-1,2) = '▲') then

begin

DBGridEhInput.Columns[iFieldCount].Title.Caption := Copy(DBGridEhInput.Columns[iFieldCount].Title.Caption,1,Length(DBGridEhInput.Columns[iFieldCount].Title.Caption)-3);

break;

end;

end;

if Column.FieldName = FSortField then

begin

if FSort = 'DESC' then

FSort := 'ASC'

else

FSort := 'DESC';

end

else begin

FSortField := Column.FieldName;

FSort := 'ASC';

end;

if FSort = 'ASC' then

Column.Title.Caption := Column.Title.Caption + ' ▲'

else

Column.Title.Caption := Column.Title.Caption + ' ▼';

AQDataInput.Sort := Column.FieldName + ' ' + FSort;

end;

二、ListView点击标题栏自动排序

1、定义全局变量

var m_bSort: boolean = False; //控制正反排序的变量

2、在程序代码最上方写上排序函数

//ListView排序的回调函数,默认的是快速排序法,也可以自己在这里做算法

function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;

var

txt1, txt2: string;

aInt: Integer;

begin

Result := 0;

if ParamSort <> 0 then

begin

try

txt1 := Item1.SubItems.Strings[ParamSort-1];

txt2 := Item2.SubItems.Strings[ParamSort-1];

if TryStrToInt(txt1, aInt) and TryStrToInt(txt2, aInt) then

begin

if m_bSort then

begin

if StrToInt(txt1) > StrToInt(txt2) then

begin

Result := 1;

end else if StrToInt(txt1) = StrToInt(txt2) then

begin

Result := 0;

end else

begin

Result := -1;

end;

end else

begin

if StrToInt(txt1) > StrToInt(txt2) then

begin

Result := -1;

end else if StrToInt(txt1) = StrToInt(txt2) then

begin

Result := 0;

end else

begin

Result := 1;

end;

end;

end else

begin

if m_bSort then

begin

Result := CompareText(txt1, txt2);

end else begin

Result := -CompareText(txt1, txt2);

end;

end;

except

end;

end else

begin

if TryStrToInt(Item1.Caption, aInt) and TryStrToInt(Item2.Caption, aInt) then

begin

if m_bSort then

begin

if StrToInt(Item1.Caption) > StrToInt(Item2.Caption) then

begin

Result := 1;

end else if StrToInt(Item1.Caption) = StrToInt(Item2.Caption) then

begin

Result := 0;

end else

begin

Result := -1;

end;

end else

begin

if StrToInt(Item1.Caption) > StrToInt(Item2.Caption) then

begin

Result := -1;

end else if StrToInt(Item1.Caption) = StrToInt(Item2.Caption) then

begin

Result := 0;

end else

begin

Result := 1;

end;

end;

end else

begin

if m_bSort then

begin

Result := CompareText(Item1.Caption,Item2.Caption);

end else

begin

Result := - CompareText(Item1.Caption,Item2.Caption);

end;

end;

end;

end;

3、在ColumnClick中增加排序调用的代码

procedure TframeDaDuiSort.ListViewDaDuiColumnClick(Sender: TObject;

Column: TListColumn);

begin

ListViewDaDui.CustomSort(@CustomSortProc, Column.Index);

m_bSort := not m_bSort;

end;

二 : 自我标点

  我要我的自我!自我有自我的性格,现在我用标点表我性格。

  多愁善感时(破折号)

  我这个人十分喜欢幻想,也许是因为我懂得了太多深奥的道理,我有一个又一个的理由能够把别人说服掉,不仅如此,我也可把别一句简简单单的事翻译成很那个那个意思就是很深奥的。翻译就是解释说明,解释说明就是破折号啦!0因此,我经常得罪人。许多同学都说我太多愁善感了。这是我的一面-多愁善感(破折号)!

  真情流露时(省略号)

  我这个人也十分容易动感情,不管是看电视,电影,只要是感人的,我都能哭个“桃花潭水深千尺“,很厉害吧!你看,哭的时候当然是省略号啦!因为眼泪成诗嘛!!那一滩滩的眼泪不就是见证嘛!

  搞笑顽皮时(逗号)

  本人除了容易动感情之外,搞笑也是我的一大特长哦!你哭的时候只要找到我了,那你不笑也得把你“逗“笑了,“逗“可是我的一大丰功伟绩哦!不信你先哭给我看,然后你就......(嘿嘿_)

  ......

  本人除了这么多的特点之外,还有许多的好玩故事,下次有机会,你来看看吧!!

 

本文标题:鼠标自动点击-DBGrid及ListView点击标题栏自动排序
本文地址: http://www.61k.com/1105896.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1