Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi columns TListBox 2

Status
Not open for further replies.

jbpelletier

Programmer
Sep 8, 2001
232
CA
Hi,

i have difficulties adding text in columns of a multi columns TlistBox. Im only able to add text in the first column... trying to find the syntax on the web and in the help but no result...:|

anyone can give me the correct syntax?

tanx
jb
 
Try:
Code:
ListBox1.Items.Add('xxxxx'^I'yyyyy'^I'zzzzzz') ;

Giovanni Caramia
 
Hi.
The main thing is that the items in the Listbox is more than the height of the listbox. The normal case would be that the Vertical scrollbar would be shown, but when you are using columns, you get the rest of the items in the next column.

Example: Change the columns property to 3, and add 30 Items in the listbox. Set the Height of the listbox to 180, and the width to 350. There you have a column example.

To add a separator in a normal listbox (Type Code and description), you have to write a new OnDrawItem Event.

Change the property Style to lbOwnerDrawFixed and add
this text in the listbox:
Column1,Column 2
Remember to change Property Columns to 0

Write this in the Listbox OnDrawItem event
Code:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
const
  SEP = ',';
var
  rowStr: String;
begin
  with TListbox(Control) do
  begin
    Canvas.FillRect(Rect);

    rowStr := Items[Index];

    Canvas.TextOut(Rect.Left, Rect.Top, Copy(rowStr, 1, Pos(SEP, rowStr) -1));
    Delete(rowStr, 1, Pos(SEP, rowStr));

    Canvas.TextOut(Rect.Left+100, Rect.Top, rowStr);
  end;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is always another way to solve it, but I prefer my way.
 
tanx Nordlund

"The normal case would be that the Vertical scrollbar would be shown, but when you are using columns, you get the rest of the items in the next column."

thats not what i was looking for, i was expecting a real 2 (or more) columns listbox.

jb


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top