Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Listbox1.Columns

Posted on 2001-09-08
5
Medium Priority
?
777 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

609 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