Navigation: TextEd > Extension and Scripts > Visual components >

TListView, TListItem

 

 

 

 

TListView displays a list of items in various ways.

Use TListView to manage and display a list of items in a form. The items can be displayed in columns with column headers and sub-items, or vertically or horizontally, with small or large icons.

 

TListItem is an individual item of a TListView control.

Use TListItem to specify the appearance and data associations of an item in a list view.


 


TListItem

 


Properties and methods



 

property string Caption;

Specifies the text that labels the item in the list.


 

property bool Checked;

Determines whether a check mark appears next to the list item.

Use Checked to indicate whether the list item represents a selected option by displaying a check mark next to the item in the list view. When Checked is true, a check mark appears next to the item. When Checked is false, no check mark appears.


 

Procedure Delete;

Deletes the list item from its list view.


 

property int ImageIndex;

Determines which image is displayed as the icon for the list item.


 

property bool Selected;

Indicates whether the list item is selected.


 

property TStrings SubItems;

Contains any strings that appear as subitems to the list item.

Use SubItems to add strings that appear in the additional columns to the right of the list view item when the list view's ViewStyle property is vsReport.


 


TListView

 


Properties and methods



 

property TAlign Align;

Determines how the control aligns within its container (parent control).

 

enum TAlign {

  alNone,

  alTop,

  alBottom,

  alLeft,

  alRight,

  alClient,

  alCustom

};

 

Ex. listView.Align = alNone;


 

property Bool AlignWithMargins;

Indicates whether a control should be constrained by margins. If AlignWithMargins is true, use the Margins property of the control to govern the spacing relative to other controls that are aligned with this one.


 

property TAnchors Anchors;

Specifies how the control is anchored to its parent.

 

enum TAnchorKind {

  akLeft,

  akTop,

  akRight,

  akBottom

};


Ex. listView.Anchors = akLeft + akTop + akRight;


 

property Bool CheckBoxes;

Specifies whether check boxes appear next to the items in the list view.


 

property TColor Color;

Specifies the background color of the control. The color value can be an hexadecimal or a color constant.


 

Defined color constants are:

clAqua, clBlack, clBlue, clCream, clDkGray, clFuchsia, clGray, clGreen, clLime, clLtGray, clMaroon, clMedGray, clMoneyGreen, clNavy, clOlive, clPurple, clRed, clSilver, clSkyBlue, clTeal, clWhite, clYellow.


 

Defined system color constants:

clNone                     White on Windows 9x, Black on NT.

clScrollBar                Current color for the of scroll bar track.

clBackground               Current background color of the Windows desktop

clActiveCaption            Current color of the title bar of the active window

clInactiveCaption          Current color of the title bar of inactive windows

clMenu                     Current background color of menus

clWindow                   Current background color of windows

clWindowFrame              Current color of window frames

clMenuText                 Current color of text on menus

clWindowText               Current color of text in windows

clCaptionText              Current color of the text on the title bar of the active window

clActiveBorder             Current border color of the active window

clInactiveBorder           Current border color of inactive windows

clAppWorkSpace             Current color of the application workspace

clHighlight                Current background color of selected text

clHightlightText           Current color of selected text

clBtnFace                  Current color of a button face

clBtnShadow                Current color of a shadow cast by a button

clGrayText                 Current color of text that is dimmed

clBtnText                  Current color of text on a button

clInactiveCaptionText      Current color of the text on the title bar of an inactive window

clBtnHighlight             Current color of the highlighting on a button

cl3DDkShadow               Windows 95 or NT 4.0 only: Dark shadow for three-dimensional display elements

cl3DLight                  Windows 95 or NT 4.0 only: Light color for three-dimensional display elements (for edges facing the light source)

clInfoText                 Windows 95 or NT 4.0 only: Text color for tool tip controls

clInfoBk                   Windows 95 or NT 4.0 only: Background color for tool tip controls

clGradientActiveCaption    Windows 98 or Windows 2000: Right side color in the color gradient of an active window's title bar.

clActiveCaption            specifies the left side color.

clGradientInactiveCaption  Windows 98 or Windows 2000: Right side color in the color gradient of an inactive window's title bar. clInactiveCaption          specifies the left side color.

clDefault                  The default color for the control to which the color is assigned.


 

Ex. listView.Color = 0x0000FF00;

Ex. listView.Color = clGreen;


 

property Bool ColumnClick;

Determines whether the column header behaves like a button.

Use ColumnClick to specify whether the OnColumnClick event should occur when the user clicks on the column header.


 

property TListColumns Columns;

Describes the properties of the columns in the list view.

Use Columns to add or delete columns in the list view, or to edit their display properties.

 

Ex.

TListColumn col = listView.Columns.Add;

col.Caption = "Details";


 

property Bool Enabled;

Controls whether the control responds to mouse, keyboard, and timer events.


 

property TFont Font;

Controls the attributes of text written on or in the control. To change to a new font, specify a new TFont object. To modify a font, change the value of the Charset, Color, Height, Name, Pitch, Size, or Style of the TFont object.

 

Ex. Edit1.Font.Size = 12;


 

property int Height;

Specifies the vertical size of the control in pixels.


Ex. Edit1.Height = 16;


 

property String Hint;

Contains the text string that can appear when the user moves the mouse over the control.


 

property TListItems Items;

Contains the list of items displayed by the list view.

Use Items to directly access the TListItem objects that represent the items in the list.

 

Ex.

TListView list = TListView.Create(form);

list.Parent = form;

list.ShowColumnHeaders = true;

list.ViewStyle = vsReport;


 

TListItem

Returned object from the list view items[] property.

 

Ex.

TListItem item;

item = list.Items.Add;

item.Caption = "John";

item.SubItems.Add("Smith");

 

item = list.Items.Add;

item.Caption = "Anna";

item.SubItems.Add("Collins");

 

 

TColumn

Returned object when creating a new column in the list view.

 

Ex.

TColumn newCol;

newCol = list.Columns.Add;

newCol.Caption = "First name";

newCol = list.Columns.Add;

newCol.Caption = "Last name";


 

property int Left;

Specifies the horizontal coordinate of the left edge of a component relative to its parent.


 

property TMargins Margins;

Specifies the margins for the control. TMargins help define the relative position between components on a form, and between the edges of the form and the component. For example, when you set a left margin for a component to 10 pixels, the component will not come closer than 10 pixels to the edge of the container, or to another component on the left edge. The number of pixels by which two components are separated is the sum of the pixels of both components.

TMargins have the class members top, bottom, left and right.

 

Ex. list.Margins.Left = 10;


 

property bool MultiSelect;

Determines whether the user can select more than one list item at a time.


 

property String Name;

Specifies the name of the component as referenced in code.


 

property TPadding Padding;

Specifies the padding of a control. Padding works similar to margins.


Ex. list.Padding.Left = 4;


 

property TWinControl Parent;

Use the Parent property to get or set the parent of this control. The parent of a control is the control that contains the control. For example, if an application includes three radio buttons in a group box, the group box is the parent of the three radio buttons, and the radio buttons are the child controls of the group box.

 

Ex.

TListView list = TListView.Create(form);

list.Parent = form;

list.Left = 8;


 

property Bool ParentColor;

To have a control use the same color as its parent control, set ParentColor to true. If ParentColor is false, the control uses its own Color property.


 

property Bool ParentFont;

Determines where a control looks for its font information.

To have a control use the same font as its parent control, set ParentFont to true. If ParentFont is false, the control uses its own Font property.


 

property TPopupMenu PopupMenu;

Identifies the pop-up menu associated with the control.


 

property Bool ReadOnly;

Determines whether the user can change the text of the edit control. To restrict the edit control to display only, set the ReadOnly property to true. Set ReadOnly to false to allow the contents of the edit control to be edited.


 

property Bool ShowColumnHeaders;

Determines whether the column headers are displayed.


 

property Bool ShowHint;

Determines whether the control displays a Help Hint when the mouse pointer rests momentarily on the control.


 

property TTabOrder TabOrder;

TabOrder is the order in which child windows are visited when the user presses the Tab key. The control with the TabOrder value of 0 is the control that has the focus when the form first appears.

 

Initially, the tab order is always the order in which the controls were added to the form. The first control added to the form has a TabOrder value of 0, the second is 1, the third is 2, and so on. Change this by changing the TabOrder property. 


 

property Bool TabStop;

Determines if the user can tab to a control.


 

property int Tag;

Stores an integer value as part of a component.


 

property int Top;

Specifies the Y coordinate of the top left corner of a control, relative to its parent or containing control in pixels.


 

property TViewStyle ViewStyle;

Determines how the list items are displayed.


TViewStyle = (vsIcon, vsSmallIcon, vsList, vsReport)


 

property Boolean Visible;

Indicates whether the control is visible.


 

property int Width;

Specifies the horizontal size of the control or form in pixels.


 


Methods



 

constructor Create(TComponent AOwner)

Creates and initializes a new TEdit object.

 

Ex.

TListView list = TListView.Create(form);

list.Parent = form;


 

procedure Free;

Destroys an object and frees its associated memory, if necessary. Visual controls added to a form is automatically destroyed when the form closes.


 

procedure Hide;

Hides the control.


 

procedure Show;

Shows the control. Use Show to set the control's Visible property to true.


 


Events



 

OnChange 

Occurs immediately after an item in the list changes.

Write an OnChange event handler to respond to changes in the list items. OnChange allows a response once the list has been successfully changed.


 

OnClick 

Occurs when the user clicks the control.

 

Ex.

 

TForm form;

TListView list;

void listClick(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil); 

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnClick = &listClick;

}


 

OnColumnClick 

Occurs when the user clicks on a column header in a list view.

 

Ex.

 

TForm form;

TListView list;

void listColumnClick(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil); 

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnColumnClick = &listColumnClick;

}


 

OnDblClick 

Occurs when the user clicks the control.


Ex.

 

TForm form;

TListView list;

void listDblClick(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil); 

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnDblClick = &listDblClick;

}


 

OnEnter 

Occurs when a control receives the input focus. Use the OnEnter event handler to cause any special processing to occur when a control becomes active.


Ex.

 

TForm form;

TListView list;

void listEnter(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnEnter = &listEnter;

}


 

OnExit 

Occurs when the input focus shifts away from one control to another. Use the OnExit event handler to provide special processing when the control ceases to be active.

 

Ex.

 

TForm form;

TListView list;

void listExit(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnExit = &listExit;

}


 

OnItemChecked 

Occurs when item is checked or unchecked.


Ex.

 

TForm form;

TListView list;

void listItemChecked(TObject Sender, TListItem Item);

{

  // Do some work here

  if (Item.Checked) {

 

  }

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnItemChecked = &listItemChecked;

}


 

OnKeyDown 

Occurs when a user presses any key while the control has focus.

 

(ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble) TShiftState;

 

Ex.

 

TForm form;

TListView list;

void listKeyDown(TObject Sender, WORD &Key, TShiftState Shift)

{

  // Do some work here

  if (Key == VK_F1) {

    // F1 was pressed, lets do something...

 

  }

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnKeyDown = &listKeyDown;

}


 

OnKeyPress 

Occurs when a key is pressed.

 

Ex.

 

TForm form;

TListView list;

void listKeyPress(TObject Sender, char &Key)

{

  // Do something

}

 

{

  form = new TForm(nil);

  list = TListView.Create(form);

  list.Parent = form;

  list.OnKeyPress = &listKeyPress;

}


 

OnKeyUp 

Occurs when the user releases a key that has been pressed.

 

(ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble) TShiftState;

 

Ex.

 

TForm form;

TListView list;

void listKeyUp(TObject Sender, WORD &Key, TShiftState Shift)

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnKeyUp = &listKeyUp;

}


 

OnMouseDown 

Occurs when the user presses a mouse button with the mouse pointer over a control.


(ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble) TShiftState;

 

enum TMouseButton {

  mbLeft,

  mbRight,

  mbMiddle

};

 

Ex.

 

TForm form;

TListView list;

void listMouseDown(TObject Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

  // Do some work here if left mouse button was pressed

  if (Button == mbLeft) {

    // Left mouse button was pressed. Lets do something...

 

  }

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnMouseDown = &listMouseDown;

}


 

OnMouseEnter 

Occurs when the user moves the mouse into a control.


Ex.

 

TForm form;

TListView list;

void listMouseEnter(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnMouseEnter = &listMouseEnter;

}


 

OnMouseLeave 

Occurs when the user moves the mouse outside of a control.


Ex.

 

TForm form;

TListView list;

void listMouseLeave(TObject Sender)

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnMouseLeave = &listMouseLeave;

}


 

OnMouseMove 

Occurs when the user moves the mouse pointer while the mouse pointer is over a control.


Ex.

 

int FMouseX,FMouseY;

TForm form;

TListView list;

void listMouseMove(TObject Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

  // Do some work here

  FMouseX = X;

  FMouseY = Y;

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnMouseMove = &listMouseMove;

}


 

OnMouseUp 

Occurs when the user releases a mouse button that was pressed with the mouse pointer over a component.

 

Ex.

 

TForm form;

TListView list;

void listMouseUp(TObject Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnMouseUp = &listMouseUp;

}


 

OnSelectItem 

Occurs when the user releases a mouse button that was pressed with the mouse pointer over a component.

 

Ex.

 

TForm form;

TListView list;

void listSelectItem(TObject Sender, TListItem Item, bool Selected);

{

  // Do some work here

}

 

{

  form = new TForm(nil);

 

  list = TListView.Create(form);

  list.Parent = form;

  list.OnSelectedItem = &listSelectedItem;

}


 


 

 

 

 

 

 

 

Copyright © 2024 Rickard Johansson