(* //
Title: Set the header icon of ListView
Description: Can be used to sort a modified icon
Design: zswang
Support: wjhu111@21cn.com
Date: 2004-03-25
// *)
Uses commctrl;
Function ListViewHeaderImages (mlistview: timagelist): boolean;
VAR
Vhandle: Thandle;
Begin
Result: = FALSE;
IF NOT ASSIGNED (MLISTVIEW).
vhandle: = listview_getheader (mlistview.handle);
IF assigned (mimages) THEN
Header_setimagelist (vhandle, mimages.handle)
Else header_setimagelist (vhandle, 0);
RESULT: = TRUE;
End; {ListViewHeaderImages}
Function ListColumnImageIndex (McOLUMN: TLISTCOLUMN;
MIMAGEINDEX: Integer; MRight: Boolean = true): boolean;
VAR
Vhandle: Thandle;
VHDITEM: THDITEM;
Begin
Result: = FALSE;
IF NOT ASSIGNED (MCOLUMN) THEN EXIT;
Vhandle: = listview_getheader (TListView (Mcolumn.collection.OWNER) .Handle);
Fillchar (vhditem, sizeof (vhditem), 0);
Header_getitem (vhandle, mcolumn.index, vhditem);
IF MIMAGEINDEX <0 THEN BEGIN
Vhditem.mask: = HDI_FORMAT;
VHDITEM.FMT: = HDF_STRING;
ELSE BEGIN
VHDITEM.MASK: = HDI_IMAGE OR HDI_FORMAT;
Vhditem.iimage: = mimageindex;
VHDITEM.FMT: = HDF_STRING OR HDF_IMAGE OR
(HDF_bitmap_on_right * ORD (MRIGHT));
END;
Header_SetItem (Vhandle, Mcolumn.index, Vhditem);
End; {ListColumnImageIndex}
// esample
Procedure TFORM1.ListView1ColumnClick (Sender: Tobject)
Column: tlistcolumn);
{$ J }
Const vindex: integer = 0;
{$ J-}
VAR
I: integer;
Begin
For i: = 0 to TListView (sender) .COLUMNS.COUNT - 1 DO
ListColumnImageIndex (TListView (sender) .COLUMNS [I], -1);
IF ABS (VINDEX) = Column.index 1 THEN
VINDEX: = -vindex
Else VINDEX: = Column.index 1;
ListColumnImageIndex (Column, ORD (VINDEX> 0));
END;
Procedure TFORM1.FormCreate (Sender: TOBJECT); Begin
ListViewHeaderImages (listview1, imagelist1);
END;