Solved

Listbox1.Columns

Posted on 2001-09-08
5
767 Views
Last Modified: 2007-11-27
Well, hello im playing with listbox columns and i got 2 questions...
 ______________________________
|R1 col 1  | col 2   | col3    |
|row2 col1 | col 2   | col3    |    <--- listbox
|row3 col1 | col2    | col3    |
|row4 col1 | col2    | col3    |
 -------------------------------

1) for example i want label1.caption :=listbox1.row2.col2.item

2) how do i decide how big each column should be?
like colum1.width = 20 etc etc

thx
0
Comment
Question by:TeChNiCh
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
you can't do this with a listbox,
use a stringgrid

meikl ;-)
0
 
LVL 10

Accepted Solution

by:
Jacco earned 200 total points
Comment Utility
The columns property (Integer) specifies the number of visible columns of the listbox. If you specify Columns > 0 then the listbox will not have a vertical scrollbar.

The number of items displayed vertically per column will be equal to:

ListBox1.ClientHeight div ListBox1.ItemHeight

The width of the columns will be:

ListBox1.ClientWidth div ListBox1.Columns

You cannot set the width of the individual columns. (Answer to Q2).

To get the Label1.Caption := ListBox1.Col2.Row2 you can use a function:

GetListBoxItem(ListBox1, 2, 2)

The function should be defined as follows:

function GetListBoxItem(aListBox: TListBox; aCol, aRow: Integer): string;
var
  liVerItems, liItemIndex: Integer;
begin
  liVerItems := aListBox.ClientHeight div aListBox.ItemHeight;
  liItemIndex := aCol * liVerItems + aRow;
  Result := aListBox.Items[liItemIndex];
end;

In the same manner you can setup a procedure that set an item using row, col indexing.

Using the ListBox in this way every item(row, col) refers to 1 item for the Items. 1 row <> 1 item.

You can also do a different thing with columns in a listbox. The standard listbox that Delphi supplies does not support them. You can also use a separator character (normally TAB). This way 1 row = 1 item. For that you have to design a component derived from TCustomListBox and use the messages LB_SETTABSTOPS. The result you get is a listbox with multiple columns but you always select by row.

Regards Jacco
0
 
LVL 2

Expert Comment

by:lucika
Comment Utility
or use TlistView:

var
  listView1: TlistView;

listView1.ViewStyle:=vsReport;

1)
  ARow:=Row;
  ACol:=Col-1;
  label1.caption:=ListView1.Items[ARow].SubItems.Strings[ACol];
2) ListView1.Columns[0].Width:=100;

0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
0
 

Expert Comment

by:SpideyMod
Comment Utility
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now