Вниз
Скачать: CL | DM;

Сортировка в ListView по SubItems...   Найти похожие ветки 

← →
BillyJeans ©   (2003-08-11 15:29) [0]

Сортировка в ListView по SubItems... Возможно ли такое стандартными методами ListView?


← →
Семен Сорокин ©   (2003-08-11 15:31) [1]

макро ListView_SortItems из commctrl.pas


← →
MBo ©   (2003-08-11 15:33) [2]

CustomSort


← →
dataMaster ©   (2003-08-11 15:37) [3]

Вот две процедуры:

1. Сортировка по строкам:
function CustomStringSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
result:=0;
if ParamSort=0 then
if (Item1.Caption)>(Item2.Caption) then Result :=1 else
if (Item1.Caption)<(Item2.Caption) then Result :=-1 else
else
if (Item1.SubItems[ParamSort-1])>(Item2.SubItems[ParamSort-1]) then Result :=1 else
if (Item1.SubItems[ParamSort-1])<(Item2.SubItems[ParamSort-1]) then Result :=-1;
end;

procedure LV_SortStr(LV : TListView; ColumnIndex : integer);
begin
LV.CustomSort(@CustomStringSortProc, ColumnIndex);
end;


2. Сортировка по датам.
function CustomDateSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
result:=0;
if ParamSort=0 then
if StrToDate(Item1.Caption)>StrToDate(Item2.Caption) then Result :=1 else
if StrToDate(Item1.Caption)<StrToDate(Item2.Caption) then Result :=-1 else
else
if StrToDate(Item1.SubItems[ParamSort-1])>StrToDate(Item2.SubItems[ParamS ort-1]) then Result :=1 else
if StrToDate(Item1.SubItems[ParamSort-1])<StrToDate(Item2.SubItems[ParamS ort-1]) then Result :=-1 else
end;

procedure LV_SortDate(LV : TListView; ColumnIndex : integer);
begin
LV.CustomSort(@CustomDateSortProc, ColumnIndex);
end;


Применение:
LV_SortStr(ListView1, 2);

либо

LV_SortDate(ListView1, 3);

в зависимости от содержимого ячеек. Думаю, что проблем быть не должно.


← →
BillyJeans ©   (2003-08-11 16:01) [4]


> dataMaster © (11.08.03 15:37) [3]

Благодарю, получилось!


← →
BillyJeans ©   (2003-08-11 16:21) [5]

Если кому интересно, заменил сортировку по строкам на следующее:

function CustomStringSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if ParamSort = 0 then Result := CompareText(Item1.Caption, Item2.Caption)
else Result := CompareText(Item1.SubItems[ParamSort-1], Item2.SubItems[ParamSort-1]);
end;



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.014 c
3-81597
nortsov
2003-07-29 13:58
2003.08.25
firebird & TQuery


3-81545
Алексей Петухов
2003-07-31 05:51
2003.08.25
TQuery и Индексы в dBase


9-81520
Barlok
2003-02-21 19:31
2003.08.25
Народ помогите, по OpenGL не работает DGLUT.PAS, пожайлуста.


1-81631
ZioN
2003-08-12 15:13
2003.08.25
Повторный запуск приложнеия


3-81582
Weare
2003-07-29 18:19
2003.08.25
Запрос SQL для TQuery.




   Наверх