Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2003.08.25;
Скачать: [xml.tar.bz2];

Вниз

Сортировка в 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 вся ветка

Форум: "Основная";
Текущий архив: 2003.08.25;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.01 c
1-81671
Вася и Ко
2003-08-11 21:09
2003.08.25
Отображении ASCII-графики


3-81543
stud
2003-07-30 16:29
2003.08.25
sql - запрос


1-81704
Vint45
2003-08-11 11:12
2003.08.25
String->PChar


1-81685
lynx
2003-08-11 15:11
2003.08.25
Run-time created объекты


7-81988
_Raven
2003-06-08 18:38
2003.08.25
Модем





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский