ListView에서 Theme를 켜고 GroupView를 True로 세팅하면 위와같이 Group으로 볼수 있다.

Group의 순서를 바꾸려면 아래와 같이 작업한다.

2010버전에서는 Group 정렬이 따로 빠져나와있지 않아서 CommCtrl을 참조했다.


1. 정렬시 전달할 사용자 데이터 구조체를 선언

type

  PGroupSortData = ^TGroupSortData;

  TGroupSortData = record

    ListView: TListview;

    ColumnIndex: Integer;

    Ascend: Boolean;

  end;



2. 정렬시 호출할 콜백 함수 구현

function ListView_GroupSort(Group1_ID: Integer; Group2_ID: Integer; pvData: Pointer): Integer; stdcall;

var

  GroupSortData: PGroupSortData;

  Str1, Str2: string;

begin

  GroupSortData := PGroupSortData(pvData);


  Str1 := GroupSortData.ListView.Groups.Items[Group1_ID].Header;

  Str2 := GroupSortData.ListView.Groups.Items[Group2_ID].Header;


  Result := CompareText( Str1, Str2 );

  if not GroupSortData.Ascend then

    Result := -Result;

end;


그룹 헤더값을 비교해서 결과값을 리턴한다.



3. uses에 CommCtrl 선언



4. 정렬 실행

var

  GroupSortData: TGroupSortData;

begin

  GroupSortData.ListView := ListView1;

  GroupSortData.Ascend := FAscend;

  GroupSortData.ColumnIndex := Column.Index;


  ListView_SortGroups( ListView1.Handle, ListView_GroupSort, @GroupSortData );


  FAscend := not FAscend;
end; 


LVM_SORTGROUPS 메시지를 쏘는 것으로 CommCtrl.pas를 참조한다.

VC의 CommCtrl.h에 있는 매크로와 동일하다.


5. exe demo & source


+ Recent posts