특정 컬럼으로 정렬하는거 있잖아요....
ColumnClick이벤트 발생시에
TListView(Sender).CustomSort(@CustomSortProc, Column.Index);
이런식으로 함수포인터를 넣어주고....
function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
var
str1, str2: string;
begin
// 비교 문자열 얻기
if ParamSort = 0 then begin
str1 := TListItem(Item1).Caption;
str2 := TListItem(Item2).Caption;
end else begin
if TListItem(Item1).SubItems.Count > ParamSort -1 then
str1 := TListItem(Item1).SubItems[ParamSort-1]
else
Str1 := '';
if TListItem(Item2).SubItems.Count > ParamSort -1 then
str2 := TListItem(Item2).SubItems[ParamSort-1]
else
Str1 := '';
end;
Result := -lstrcmp(PChar(str1), PChar(str2));
if SortToggle then Result := -Result;
end;
이런식으로밖에 코드가 없던데... 문자열 비교해 주고 어느 값이 큰지밖에 안 넘어가는데 어떻게 정렬이 되죠???
제 소스가 아니라 다른 소스 보다가 궁금해서 올립니다.....
고수님들의 답변 부탁드립니다....
> Result := -lstrcmp(PChar(str1), PChar(str2));
위코드에서 값들을 비교를 하네네요...
> if SortToggle then Result := -Result;
그 아래코드는 SortToggle에 따라서 정렬순서를 반대로 바꾸구요...
TListView.CustomSort메소드에서 아이템들을 콜백함수에 넣어서 결과값을 가지고 비교를 합니다.
^^ 항상 즐코하세요...
^^ 항상 즐코하세요...
백승환 wrote:
> 특정 컬럼으로 정렬하는거 있잖아요....
>
> ColumnClick이벤트 발생시에
>
> TListView(Sender).CustomSort(@CustomSortProc, Column.Index);
>
> 이런식으로 함수포인터를 넣어주고....
>
> function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
> var
> str1, str2: string;
> begin
> // 비교 문자열 얻기
> if ParamSort = 0 then begin
> str1 := TListItem(Item1).Caption;
> str2 := TListItem(Item2).Caption;
> end else begin
> if TListItem(Item1).SubItems.Count > ParamSort -1 then
> str1 := TListItem(Item1).SubItems[ParamSort-1]
> else
> Str1 := '';
> if TListItem(Item2).SubItems.Count > ParamSort -1 then
> str2 := TListItem(Item2).SubItems[ParamSort-1]
> else
> Str1 := '';
> end;
>
> Result := -lstrcmp(PChar(str1), PChar(str2));
>
> if SortToggle then Result := -Result;
> end;
>
> 이런식으로밖에 코드가 없던데... 문자열 비교해 주고 어느 값이 큰지밖에 안 넘어가는데 어떻게 정렬이 되죠???
>
> 제 소스가 아니라 다른 소스 보다가 궁금해서 올립니다.....
>
> 고수님들의 답변 부탁드립니다....