Solved

Listbox1.Columns

Posted on 2001-09-08
5
771 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
ID: 6467540
you can't do this with a listbox,
use a stringgrid

meikl ;-)
0
 
LVL 10

Accepted Solution

by:
Jacco earned 200 total points
ID: 6468211
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
ID: 6468212
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
ID: 7872452
0
 

Expert Comment

by:SpideyMod
ID: 8145014
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run video youtube webbrowse 10 65
How to build JSON File in Delphi 6 3 46
Multi-layered image in FireMonkey 9 50
Delphi: sending SMS on android platform 1 39
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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