ListView

Are there Listview-components where i can show a little trianlge in the header when it is sorted.
Or can i paint and write Text to the header of a standard Listview ?
snoopy_SpyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KECommented:
What Delphi version do you use ?

In D5 you can have images on headers.

Regards
0
snoopy_SpyAuthor Commented:
Delphi 4.0
0
hubdogCommented:
//this is a example of showing a graph
on listview header

unit IconList;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, Commctrl;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    ArrowDown, NoArrow, ArrowUp: HBitmap;
    FBitmap: TBitmap;
    FAtoZ: Boolean;
    OldCol: Byte;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
{$R Arrows.res}
var  AtoZOrder: Boolean;

procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer; stdcall;
begin
  case ParamSort of  //Column
    0://Sort Main column.
    if AtoZOrder then
      Result:=lstrcmp(PChar(TListItem(Item1).Caption), PChar(TListItem(Item2).Caption))
    else
      Result:=-lstrcmp(PChar(TListItem(Item1).Caption), PChar(TListItem(Item2).Caption));
  else //Sort one of the subcolumns (subitems).
    if AtoZOrder then
      Result:=lstrcmp(PChar(TListItem(Item1).SubItems[ParamSort-1]), PChar(TListItem(Item2).SubItems[ParamSort-1]))
    else
      Result:=-lstrcmp(PChar(TListItem(Item1).SubItems[ParamSort-1]), PChar(TListItem(Item2).SubItems[ParamSort-1]));
  end;
end;
var hditem:THdItem;
    I: Byte;
begin
  if OldCol=Column.Index then
    FAtoZ:=not FAtoZ
  else
    OldCol:=Column.Index;
  AtoZOrder:=FAtoZ;
  ListView1.CustomSort(@CustomSortProc, Column.Index);
  for I:=0 to ListView1.Columns.Count-1 do
  begin
    FBitmap.Releasehandle;
    if I=Column.Index then
    begin
      if AtoZOrder then
        FBitmap.Handle:=ArrowDown
      else
        FBitmap.Handle:=ArrowUp
    end
    else
       FBitmap.Handle:=NoArrow;
    hditem.Mask := HDI_FORMAT;
    Header_GetItem(GetDlgItem(ListView1.Handle,0),I,hditem);
    hditem.Mask:=HDI_BITMAP or HDI_FORMAT;
    hditem.fmt:=hditem.fmt or HDF_BITMAP or HDF_BITMAP_ON_RIGHT;//
//show bitmap on right
    hditem.hbm:=FBitmap.Handle;
    Header_SetItem(GetDlgItem(ListView1.Handle,0),I,hditem);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ArrowUp:=LoadBitmap(hInstance, 'ARROWUP');
  ArrowDown:=LoadBitmap(hInstance, 'ARROWDOWN');
  NoArrow:=LoadBitmap(hInstance, 'NOARROW');
  FBitmap:=TBitmap.Create;
  ListView1ColumnClick(Sender,ListView1.Columns[0]);

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FBitmap.ReleaseHandle;
  FBitmap.Free;
  DeleteObject(ArrowUp);
  DeleteObject(ArrowDown);
  DeleteObject(NoArrow);
end;

end.
//dfmÎļþ
object Form1: TForm1
  Left = 92
  Top = 164
  Width = 472
  Height = 314
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  OnClose = FormClose
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object ListView1: TListView
    Left = 4
    Top = 14
    Width = 410
    Height = 109
    Columns = <
      item
        Caption = 'AAA'
        Width = 70
      end
      item
        Caption = 'BBB'
        Width = 100
      end
      item
        Caption = 'CCC'
        Width = 70
      end
      item
        Caption = 'DDD'
        Width = 150
      end>
    Items.Data = {
      E40000000500000000000000FFFFFFFFFFFFFFFF030000000000000005537461
      6D330365656503747474036D6D6D00000000FFFFFFFFFFFFFFFF030000000000
      0000055374616D3103616161036262620363636300000000FFFFFFFFFFFFFFFF
      0300000000000000055374616D35036F6F6F03707070037A7A7A00000000FFFF
      FFFFFFFFFFFF0300000000000000055374616D32036A6A6A0372727203757575
      00000000FFFFFFFFFFFFFFFF0300000000000000055374616D3403717171036E
      6E6E03626262FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      FFFFFFFF}
    TabOrder = 0
    ViewStyle = vsReport
    OnColumnClick = ListView1ColumnClick
  end
end
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.