listview OnCustomDrawSubItemEx event
Return to Introduction  Previous page  Next page
Applies to
acListView and acDBListView components.  

  TacListViewCustomDrawSubItemExEvent = procedure(Sender: TObject; Canvas: TCanvas; Rect: TRect; Item: TListItem; SubItem: Integer; State: TCustomDrawStatevar DefaultDraw: Boolean) of object;  
property OnCustomDrawSubItemEx: TacListViewCustomDrawSubItemExEvent;  

The OnCustomDrawSubItemEx event occurs when a subitem must be rendered in the list-view. This is a bug-free replacement of standard OnCustomDrawSubItem event existing in usual list-view controls. Additionally it passes to the event handler the Canvas and drawing rectangle (Rect).  
Write code in an OnCustomDrawSubItemEx handler to draw to the subitems that appear in additional columns to the right of each item when ViewStyle is vsReport. Use the Canvas property passed to the handler as a drawing surface. (Do NOT use the list-view's Canvas!! This is major bug of standard OnCustomDrawSubItem event. The owner's font appears broken on Win95/98/ME after first custom drawing.)  
The Sender Parameter specifies the list view that owns the subitems. The Item parameter is the current Item being drawn. The SubItem parameter is the index of the subitem of that list item in its SubItems property. The State indicates various attributes that can affect the way the subitem is drawn. Set DefaultDraw to False to prevent the list view from adding the subitem's text after the event handler exits.  

procedure TForm1.ListView1CustomDrawSubItemEx(Sender: TObject;  
  Canvas: TCanvas; Rect: TRect; Item: TListItem; SubItem: Integer;  
  State: TCustomDrawState; var DefaultDraw: Boolean);  
  if Columns[SubItem].ImageIndex <> -1 then  
    ImageList1.Draw(Canvas, Rect.Left + 5, Rect.Top + 10);  
    DefaultDraw := False;  

Custom drawing of sub-items of the list-view controls supported in Delphi 4/C++ Builder 4 and higher. This event does not exists in Delphi 2/3 or C++ Builder 3.