Solved

Listbox1.Columns

Posted on 2001-09-08
5
772 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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