?
Solved

Listbox1.Columns

Posted on 2001-09-08
5
Medium Priority
?
775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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
 

Expert Comment

by:SpideyMod
ID: 8145014
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 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