Class TTreeListView

Unit

Declaration

type TTreeListView = class(TCustomControl)

Description

This is the main TreeListView-class and the only class you need to create yourself.

Simple Example (use in FormCreate), which creates two items one called 'Item' and one called 'Child' where latter shows the value 'Property' in the second column (the tree with the names will be in the first column):

//Standard component creation
List:=TTreeListView.create(self);
List.Parent:=self;
List.Align:=alClient;
//Create Columns
List.Columns.Clear;
List.Columns.Add.Text:='A';
List.Columns.Add.Text:='B';
//Create Items
List.BeginUpdate;
List.Items.Add('Item').SubItems.Add('Child').RecordItemsText[1]:='Property';
List.EndUpdate;



Generally, the treelistview shows its items in a 2d record layout, with the vertical items of a treeview and the horizontal items of a listview.
Former are just called "items", latter are called "record items"; and each record item is associated to a normal item.



Creating normal items

The simplest way to create a new item is by calling the method treelistview.Items.Add('text').
This will add a new item with text "text" to the first level of the tree.
If you want to create an item on a deeper level of the tree i.e. as sub item to a given parent item, you can call either treelistview.Items.Add(parent, 'text') or parent.subitems.add('text');
If you're going to add several items, you should call treelistview.BeginUpdate and treelistview.EndUpdate.



Creating record items

To add a record item to a given item e.g. to set its text in column i, you can just call item.RecordItemsText[i]:='text';

Hierarchy

Overview

Fields

Public hotTrackedRecordItem:TTreeListRecordItem;

Methods

Public procedure UpdateScrollSizeH;
Public procedure UpdateScrollSizeV;
Public procedure UpdateScrollSize;
Public constructor Create(aowner:TComponent); override;
Public procedure loaded; override;
Public function GetItemAtPos(const y:integer):TTreeListItem;
Public function GetRecordItemAtPos(const x,y:integer):TTreeListRecordItem;
Public procedure BeginUpdate;
Public procedure EndUpdate;
Public function VisibleRowCount:longint;
Public procedure sort;
Public procedure ensureVisibility(item: TTreeListItem;column: longint=-1);
Public function search(searchFor: string; searchFields:cardinal; backward: boolean=false;extendSelection: boolean=false): TFindState; overload;
Public function ColumnFromOriginalIndex(index: longint): THeaderSection;
Public procedure ColumnsAutoSize;
Public procedure CreateUserColumnVisibilityPopupMenu();
Public function serializeColumnWidths: string;
Public function serializeColumnOrder: string;
Public function serializeColumnVisibility: string;
Public procedure deserializeColumnWidths(s: string);
Public procedure deserializeColumnOrder(s: string);
Public procedure deserializeColumnVisibility(s: string);
Public procedure CreateSearchBar();
Public procedure Notification(AComponent: TComponent; Operation: TOperation); override;
Public procedure WndProc(var message:TMessage); override;
Public procedure sheduleInternRepaint();
Public procedure internRepaint();
Public procedure invalidateItem(item: TTreeListItem=nil);
Public procedure invalidateAll();
Public procedure internDraw();
Public procedure internPaint(calledFromPaintingEvent: boolean=false);
Public procedure Paint; override;
Public destructor Destroy; override;

Properties

Public property selCount: longint read F_SelCount;
Public property focused: TTreeListItem read F_Focused write SetFocused;
Public property Selected: TTreeListItem read F_Focused write SetSelected;
Public property SortColumn: longint read F_SortColumn write SetSortColumn;
Public property SearchBar: TSearchBar read F_SearchBar;
Public property TopPos: integer read GetTopPos;
Public property TopItem: TTreeListItem read GetTopItem write SetTopItem;
Public property TopItemIsEvenItem: boolean read GetTopItemEven;
Public property TopItemVisualIndex: integer read GetTopItemVisualIndex;
Public property DrawingEvenItem: boolean read F_DrawingEvenItem;
Public property DrawingYPos: longint read F_DrawingYPos;
Public property DrawingRecordItemRect: TRect read F_DrawingRecordItemRect;
Published property Options: TTreeListViewOptions read F_Options write SetOptions;
Published property Columns: THeaderSections read GetColumns write SetColumns;
Published property RowHeight: integer read F_RowHeight write SetRowHeight;
Published property Images: TImageList read F_ImageList write setImageList;
Published property HorizontalLineMode: TLineMode read F_HorizontalLines write SetHorizontalLines;
Published property HorizontalLineColor: TColor read F_HorizontalLineColor write SetHorizontalLineColor;
Published property VerticalLineMode: TLineMode read F_VerticalLines write SetVerticalLines;
Published property VerticalLineColor: TColor read F_VerticalLineColor write SetVerticalLineColor;
Published property RootLineMode: TLineMode read F_RootLines write SetRootLines;
Published property RootLineColor: TColor read F_RootLineColor write SetRootLineColor;
Published property ColorSearchMark: tcolor read F_ColorSearchMark write SetColorSearchMark;
Published property ColorSearchMarkField: tcolor read F_ColorSearchMarkField write SetColorSearchMarkField;
Published property ExpandMode: TExpandMode read F_ExpandMode write SetExpandMode;
Published property HotTrackFont: TFont read F_HotTrackFont write SetHotTrackFont;
Published property Font;
Published property SelectedFont: TFont read F_SelectedFont write SetSelectedFont;
Published property SelectedHotTrackFont: TFont read F_SelectedHotTrackFont write SetSelectedHotTrackFont;
Published property StripedOddColor: TColor read F_StripedOddColor write SetStripedOddColor;
Published property StripedEvenColor: TColor read F_StripedEvenColor write SetStripedEvenColor;
Published property SelectBackColor: TColor read F_SelectBackColor write SetSelectBackColor;
Published property ButtonColor: TColor read F_ButtonColor write SetButtonColor;
Published property BackGroundColor: TColor read F_BgColor write SetBgColor;
Published property Items: TTreeListItems read F_Items write SetItems;
Published property Scrollbars: TScrollStyle read F_ScrollStyle write SetScrollStyle;
Published property HeaderVisible: boolean read F_HeaderVisible write SetHeaderVisible;
Published property OnCompareItems: TCompareTreeListItemsEvent read F_OnCompareItems write F_OnCompareItems;
Published property OnUserSortItemsEvent: TUserSortItemsEvent read F_OnUserSortItems write F_OnUserSortItems;
Published property OnItemsSortedEvent: TNotifyEvent read F_OnItemsSorted write F_OnItemsSorted;
Published property OnVScrollBarChange: TNotifyEvent read F_VScrollBarChange write F_VScrollBarChange;
Published property OnHScrollBarChange: TNotifyEvent read F_HScrollBarChange write F_HScrollBarChange;
Published property OnCustomBgDraw: TCustomBackgroundDrawEvent read F_CustomBgDraw write F_CustomBgDraw;
Published property OnCustomItemDraw: TCustomItemDrawEvent read F_CustomItemDraw write F_CustomItemDraw;
Published property OnCustomRecordItemDraw: TCustomRecordItemDrawEvent read F_CustomRecordItemDraw write F_CustomRecordItemDraw;
Published property OnCustomRecordItemPositioning: TCustomRecordItemPositioningEvent read F_CustomRecordItemPositioningEvent write F_CustomRecordItemPositioningEvent;
Published property OnClickAtRecordItem: TRecordItemEvent read F_ClickAtRecordItem write F_ClickAtRecordItem;
Published property OnClickAtItem: TItemEvent read F_ClickAtItem write F_ClickAtItem;
Published property OnSelect: TItemEvent read F_OnSelect write F_OnSelect;
Published property OnItemCollapsed: TItemEvent read F_OnItemCollapsed write F_OnItemCollapsed;
Published property OnItemExpanded: TItemEvent read F_OnItemExpanded write F_OnItemExpanded;
Published property OnHeaderSectionResize: TCustomSectionNotifyEvent read F_HeaderSectionResize write F_HeaderSectionResize;
Published property OnHeaderSectionTrack: TCustomSectionTrackEvent read F_HeaderSectionTrack write F_HeaderSectionTrack;
Published property TabStop default true;
Published property TabOrder;
Published property Align;
Published property Anchors;
Published property Constraints;
Published property DragCursor;
Published property DragKind ;
Published property DragMode ;
Published property Hint ;
Published property PopupMenu;
Published property ShowHint ;
Published property OnDockDrop;
Published property OnDockOver;
Published property OnEnter;
Published property OnExit;
Published property OnGetSiteInfo;
Published property OnKeyDown;
Published property OnKeyPress;
Published property OnKeyUp;
Published property OnMouseWheel;
Published property OnMouseWheelDown;
Published property OnMouseWheelUp;
Published property OnUnDock;
Published property OnClick;
Published property OnConstrainedResize;
Published property OnDblClick;
Published property OnDragDrop;
Published property OnDragOver;
Published property OnEndDock;
Published property OnEndDrag;
Published property OnMouseDown;
Published property OnMouseMove;
Published property OnMouseUp;
Published property OnResize;
Published property OnStartDock;
Published property OnStartDrag;

Description

Fields

Public hotTrackedRecordItem:TTreeListRecordItem;

Item currently touched by the mouse

Methods

Public procedure UpdateScrollSizeH;

Warning: this symbol is deprecated.

Recalculates the necessary scrollbar properties
Normally you don't need to call this

Public procedure UpdateScrollSizeV;

Warning: this symbol is deprecated.

Recalculates the necessary scrollbar properties
Normally you don't need to call this

Public procedure UpdateScrollSize;

Warning: this symbol is deprecated.

Recalculates the necessary scrollbar properties
Normally you don't need to call this

Public constructor Create(aowner:TComponent); override;

Create

Public procedure loaded; override;
 
Public function GetItemAtPos(const y:integer):TTreeListItem;

Returns the item at position y

Public function GetRecordItemAtPos(const x,y:integer):TTreeListRecordItem;

Returns the record item at position x,y
Notice that it doesn't check for visibility, e.g you can use negative coordinates or find items hidden by the scrollbars

Public procedure BeginUpdate;

Notifies the control that the items are changed, so it will not redrawn itself.
Never forget to use this, otherwise it will be very slow.

Public procedure EndUpdate;

Stops the redraw block and redraws everything

Public function VisibleRowCount:longint;

Count of visible lines

Public procedure sort;

Sorts the items according to the current sorting options

Public procedure ensureVisibility(item: TTreeListItem;column: longint=-1);

Makes item visible, this includes scrolling and expanding of items
If column is not -1 it scroll horizontally to the beginning/ending of this column if it isn't visible

Public function search(searchFor: string; searchFields:cardinal; backward: boolean=false;extendSelection: boolean=false): TFindState; overload;

This searches the text searchFor in searchFields and marks it.

Parameters
searchFields
Bit-wise combination of column numbers. Use 1 shl i for column i. (you can only use the first 32 columns)
backward
Specifies search direction
extendSelection
set this to true for an incremental search
Public function ColumnFromOriginalIndex(index: longint): THeaderSection;

If the columns can be dragged this will return them in the old order

Public procedure ColumnsAutoSize;
 
Public procedure CreateUserColumnVisibilityPopupMenu();

Creates a popupmenu to hide/show columns
You need to call this method after every removing/creating of columns, because the TreeListView doesn't known when the columns are changed, since you have direct access to the headercontrol sections.
This needs FPC

Public function serializeColumnWidths: string;

save the widths of the columns in a string

See also
deserializeColumnWidths
load the widths of the columns from a string
Public function serializeColumnOrder: string;

save the order of the columns in a string (needs FPC)

See also
deserializeColumnOrder
load the order of the columns from a string (needs FPC)
Public function serializeColumnVisibility: string;

save the visibility of the columns in a string (needs FPC)

See also
deserializeColumnVisibility
load the visibility of the columns from a string (needs FPC)
Public procedure deserializeColumnWidths(s: string);

load the widths of the columns from a string

See also
serializeColumnWidths
save the widths of the columns in a string
Public procedure deserializeColumnOrder(s: string);

load the order of the columns from a string (needs FPC)

See also
serializeColumnOrder
save the order of the columns in a string (needs FPC)
Public procedure deserializeColumnVisibility(s: string);

load the visibility of the columns from a string (needs FPC)

See also
serializeColumnVisibility
save the visibility of the columns in a string (needs FPC)
Public procedure CreateSearchBar();

Creates a FireFox like SearchBar

Public procedure Notification(AComponent: TComponent; Operation: TOperation); override;
 
Public procedure WndProc(var message:TMessage); override;
 
Public procedure sheduleInternRepaint();

This method will soon repaint all items. This means as soon as the calling functions finished (= returns to the application message loop) and all pending messages are processed, internRepaint will be called

See also
internPaint
This method will paint all changed items on the screen.
sheduleInternRepaint
This method will soon repaint all items.
invalidateAll
This invalidates all items, so the whole control will be redrawn if next painting occurs
invalidateItem
This invalidates the passed item, so that it will be redrawn if the next painting occurs
Public procedure internRepaint();

This method forces a redraw of all items (=invalidateAll and internPaint)

See also
internPaint
This method will paint all changed items on the screen.
sheduleInternRepaint
This method will soon repaint all items.
invalidateAll
This invalidates all items, so the whole control will be redrawn if next painting occurs
invalidateItem
This invalidates the passed item, so that it will be redrawn if the next painting occurs
Public procedure invalidateItem(item: TTreeListItem=nil);

This invalidates the passed item, so that it will be redrawn if the next painting occurs

See also
internPaint
This method will paint all changed items on the screen.
sheduleInternRepaint
This method will soon repaint all items.
internRepaint
This method forces a redraw of all items (=invalidateAll and internPaint)
invalidateAll
This invalidates all items, so the whole control will be redrawn if next painting occurs
Public procedure invalidateAll();

This invalidates all items, so the whole control will be redrawn if next painting occurs

See also
internPaint
This method will paint all changed items on the screen.
sheduleInternRepaint
This method will soon repaint all items.
internRepaint
This method forces a redraw of all items (=invalidateAll and internPaint)
invalidateItem
This invalidates the passed item, so that it will be redrawn if the next painting occurs
Public procedure internDraw();

This method draws all changed (=invalidated) items in the double buffer. There should never be a reason to call this

See also
internPaint
This method will paint all changed items on the screen.
sheduleInternRepaint
This method will soon repaint all items.
internRepaint
This method forces a redraw of all items (=invalidateAll and internPaint)
invalidateAll
This invalidates all items, so the whole control will be redrawn if next painting occurs
invalidateItem
This invalidates the passed item, so that it will be redrawn if the next painting occurs
Public procedure internPaint(calledFromPaintingEvent: boolean=false);

This method will paint all changed items on the screen. This means it will call internDraw to draw all changed item in the double buffer and then copy the changed areas of the double buffer on the screen

See also
sheduleInternRepaint
This method will soon repaint all items.
internRepaint
This method forces a redraw of all items (=invalidateAll and internPaint)
invalidateAll
This invalidates all items, so the whole control will be redrawn if next painting occurs
invalidateItem
This invalidates the passed item, so that it will be redrawn if the next painting occurs
Public procedure Paint; override;

This is the normal Delphi/Lazarus painting routine called when a paint message is received. You should call it seldom.

See also
sheduleInternRepaint
This method will soon repaint all items.
internRepaint
This method forces a redraw of all items (=invalidateAll and internPaint)
invalidateAll
This invalidates all items, so the whole control will be redrawn if next painting occurs
invalidateItem
This invalidates the passed item, so that it will be redrawn if the next painting occurs
Public destructor Destroy; override;
 

Properties

Public property selCount: longint read F_SelCount;

Count of selected items

Public property focused: TTreeListItem read F_Focused write SetFocused;

Currently focused item, it is not necessarily selected.
Setting this property will not select the new item

Public property Selected: TTreeListItem read F_Focused write SetSelected;

This is the same as Focused, but setting this property will select the item and deselect every other one

Public property SortColumn: longint read F_SortColumn write SetSortColumn;

Column currently used for sorting

Public property SearchBar: TSearchBar read F_SearchBar;

This a FireFox like search bar, call createSearchBar before using (this property)

Public property TopPos: integer read GetTopPos;

V-Scrollposition calculated in pixels (=position of Items[0])

Public property TopItem: TTreeListItem read GetTopItem write SetTopItem;

Visible item with the least real index (can be nil)

Public property TopItemIsEvenItem: boolean read GetTopItemEven;

Is the top item even (used for striping)

Public property TopItemVisualIndex: integer read GetTopItemVisualIndex;

Index of the top item, if all visible items were in a single list

Public property DrawingEvenItem: boolean read F_DrawingEvenItem;

Is the currently drawn item even (only valid during custom draw events, having this as property prevents parameter cluttering)

Public property DrawingYPos: longint read F_DrawingYPos;

Y-Position of the currently drawn item (only valid during custom draw events, having this as property prevents parameter cluttering)

Public property DrawingRecordItemRect: TRect read F_DrawingRecordItemRect;

boundaries of the currently drawn record item (only valid during custom draw events, having this as property prevents parameter cluttering)

Published property Options: TTreeListViewOptions read F_Options write SetOptions;

General appearance/behaviour options

See also
TTreeListViewOption
General appearance/behaviour options
Published property Columns: THeaderSections read GetColumns write SetColumns;

All columns

Published property RowHeight: integer read F_RowHeight write SetRowHeight;

Height of a row

Published property Images: TImageList read F_ImageList write setImageList;

ImageList used to get the images for items using the TTreeListView.ImageIndex property

Published property HorizontalLineMode: TLineMode read F_HorizontalLines write SetHorizontalLines;

Determines how/if lines are drawn between the items

Published property HorizontalLineColor: TColor read F_HorizontalLineColor write SetHorizontalLineColor;
 
Published property VerticalLineMode: TLineMode read F_VerticalLines write SetVerticalLines;

Determines how/if lines are drawn between the columns

Published property VerticalLineColor: TColor read F_VerticalLineColor write SetVerticalLineColor;
 
Published property RootLineMode: TLineMode read F_RootLines write SetRootLines;

Determines how/if lines are drawn to connect the tree items

Published property RootLineColor: TColor read F_RootLineColor write SetRootLineColor;
 
Published property ColorSearchMark: tcolor read F_ColorSearchMark write SetColorSearchMark;
 
Published property ColorSearchMarkField: tcolor read F_ColorSearchMarkField write SetColorSearchMarkField;
 
Published property ExpandMode: TExpandMode read F_ExpandMode write SetExpandMode;

Determines how/if the user is allowed to collapse/expand items

Published property HotTrackFont: TFont read F_HotTrackFont write SetHotTrackFont;
 
Published property Font;
 
Published property SelectedFont: TFont read F_SelectedFont write SetSelectedFont;
 
Published property SelectedHotTrackFont: TFont read F_SelectedHotTrackFont write SetSelectedHotTrackFont;
 
Published property StripedOddColor: TColor read F_StripedOddColor write SetStripedOddColor;
 
Published property StripedEvenColor: TColor read F_StripedEvenColor write SetStripedEvenColor;
 
Published property SelectBackColor: TColor read F_SelectBackColor write SetSelectBackColor;
 
Published property ButtonColor: TColor read F_ButtonColor write SetButtonColor;

Color of the expand/collaps button

Published property BackGroundColor: TColor read F_BgColor write SetBgColor;
 
Published property Items: TTreeListItems read F_Items write SetItems;

All the items, use items.add to create new ones

Published property Scrollbars: TScrollStyle read F_ScrollStyle write SetScrollStyle;
 
Published property HeaderVisible: boolean read F_HeaderVisible write SetHeaderVisible;
 
Published property OnCompareItems: TCompareTreeListItemsEvent read F_OnCompareItems write F_OnCompareItems;

Event which is called when two items are compared during sorting
The default sorting is case-insensitive lexicographical on text and numerical on number string parts, every level is sorted on its own, parents are not changed

Published property OnUserSortItemsEvent: TUserSortItemsEvent read F_OnUserSortItems write F_OnUserSortItems;

Called when the user clicks on the header to resort the items

Published property OnItemsSortedEvent: TNotifyEvent read F_OnItemsSorted write F_OnItemsSorted;

Called after the items have been sorted

Published property OnVScrollBarChange: TNotifyEvent read F_VScrollBarChange write F_VScrollBarChange;
 
Published property OnHScrollBarChange: TNotifyEvent read F_HScrollBarChange write F_HScrollBarChange;
 
Published property OnCustomBgDraw: TCustomBackgroundDrawEvent read F_CustomBgDraw write F_CustomBgDraw;

This is called before/after the items are drawn

Published property OnCustomItemDraw: TCustomItemDrawEvent read F_CustomItemDraw write F_CustomItemDraw;

This is called before/after an item is drawn

See also
TTreeListItem.PaintTo,
Published property OnCustomRecordItemDraw: TCustomRecordItemDrawEvent read F_CustomRecordItemDraw write F_CustomRecordItemDraw;

This is called before/after any record items is drawn

Published property OnCustomRecordItemPositioning: TCustomRecordItemPositioningEvent read F_CustomRecordItemPositioningEvent write F_CustomRecordItemPositioningEvent;

This is called when the position of a record item is calculated

Published property OnClickAtRecordItem: TRecordItemEvent read F_ClickAtRecordItem write F_ClickAtRecordItem;

Called when the user clicks on a record item

Published property OnClickAtItem: TItemEvent read F_ClickAtItem write F_ClickAtItem;

Called when the user clicks on an item (if you need the column use OnClickAtRecordItem)

Published property OnSelect: TItemEvent read F_OnSelect write F_OnSelect;

Called when an item is selected or deselected

Published property OnItemCollapsed: TItemEvent read F_OnItemCollapsed write F_OnItemCollapsed;

Called when an item is collapsed

Published property OnItemExpanded: TItemEvent read F_OnItemExpanded write F_OnItemExpanded;

Called when an item is expanded

Published property OnHeaderSectionResize: TCustomSectionNotifyEvent read F_HeaderSectionResize write F_HeaderSectionResize;
 
Published property OnHeaderSectionTrack: TCustomSectionTrackEvent read F_HeaderSectionTrack write F_HeaderSectionTrack;
 
Published property TabStop default true;
 
Published property TabOrder;
 
Published property Align;
 
Published property Anchors;
 
Published property Constraints;
 
Published property DragCursor;
 
Published property DragKind ;
 
Published property DragMode ;
 
Published property Hint ;

You can't use this if tooltips is true

Published property PopupMenu;
 
Published property ShowHint ;
 
Published property OnDockDrop;
 
Published property OnDockOver;
 
Published property OnEnter;
 
Published property OnExit;
 
Published property OnGetSiteInfo;
 
Published property OnKeyDown;
 
Published property OnKeyPress;
 
Published property OnKeyUp;
 
Published property OnMouseWheel;
 
Published property OnMouseWheelDown;
 
Published property OnMouseWheelUp;
 
Published property OnUnDock;
 
Published property OnClick;
 
Published property OnConstrainedResize;
 
Published property OnDblClick;
 
Published property OnDragDrop;
 
Published property OnDragOver;
 
Published property OnEndDock;
 
Published property OnEndDrag;
 
Published property OnMouseDown;
 
Published property OnMouseMove;
 
Published property OnMouseUp;
 
Published property OnResize;
 
Published property OnStartDock;
 
Published property OnStartDrag;
 

Generated by PasDoc 0.16.0.