1. About.com
  2. Computing & Technology
  3. Delphi

Discuss in my forum

Show TListBox Items in Multiple Columns

By , About.com Guide

TListBox Columns

TlistBox Columns

Delphi's TListBox control displays a collection of items in a scrollable list.

By design, a listbox displays its items in one column.

If you want to display several items in one row, thus have multiple columns in a list box, you can use the next approach:

Set the TabWidth property - it specifies the width of the columns in pixels.

When you add items to the list box, separate the columns with '^I', that is capital "i", like in:

 begin
   ListBox1.Items.Add('First'^I'Second'^I'Third') ;
   ListBox1.Items.Add('C1R1'^I'C2R1'^I'C3R1') ;
   ListBox1.Items.Add('C1R2'^I'C2R2'^I'C3R2') ;
   ListBox1.Items.Add('C1R3'^I'C2R3'^I'C3R3') ;
   ListBox1.Items.Add('C1R4'^I'C2R4'^I'C3R4') ;
   ListBox1.Items.Add('C1R5'^I'C2R5'^I'C3R5') ;
   ListBox1.Items.Add('C1R6'^I'C2R6'^I'C3R6') ;
   ListBox1.Items.Add('C1R7'^I'C2R7'^I'C3R7') ;
   ListBox1.Items.Add('C1R8'^I'C2R8'^I'C3R8') ;
   ListBox1.Items.Add('C1R9'^I'C2R9'^I'C3R9') ;
 end;
 
Delphi tips navigator:
» Hide/Show Tray icons
« Get text from the control at pos x,y on screen

©2012 About.com. All rights reserved. 

A part of The New York Times Company.