Thanks in Advance.
--
Alvaro Garriga, Programmer Analyst
TransCore, An SAIC Company
Phone: 770-447-6831 Ext. 3066 / Fax: 770-449-7268
Email: agc@*khj.com
( change *khj to jhk for real address )
In Delphi 3, TListView has a property FullRowSelect: Boolean. You can
setthis to true. Before Delphi 3, you'd have to post a Message to the
control.
> 2- ¿ How to add Items to the List View at run time? what is the
> fastest
> way of doing it ?
var NewItem: TListItem;
SomeListView: TListView;
begin
NewItem := SomeListView.Items.Add;
NewItem.Caption := 'the caption you need';
end;
I don't know what the fastest way is. But ListViews are never fast, I
guess...
Try adding 10.000 items and showing the progress in a ProgressBar.
You'll be surprised...
> 3- ¿ How can I can I keep the list sorted ?.
I am not sure, but check out OnColumnCompare event. There you can
definea handler to compare two ListItems after your own algorithm
(sorting is nothing
but repeated comparison...). And see the below approach for storing
additional
column information.
> 4- ¿ How can I sort Up/down base on the column Click event ?
Store the sort direction anywhere, and revert it on every ColumnClick
event.To store information about the ListView columns, I recommend
associating
objects of some class. Try this:
- ListItems in the ListView have SubItems - these make the columns.
- SubItems is a StringList.
- StringList contains Strings and Objects (!)
If you make yourself a class that you can create objects from and
associate them
with the SubItems, you can store any information in the object for each
column.
This is a *very* powerful approach, and not as complicated as it sounds.
Let me know if I should give you more detail.
Cheers,
- Jochen
Jochen Bender wrote:
> ------------------------------------------------------------------------
>
> Jochen Bender <jochen...@psplus.de>
> Senior Developer
> PSplus GmbH
>
> Jochen Bender
> Senior Developer <jochen...@psplus.de>
> PSplus GmbH
> Netscape Conference Address
> Netscape Conference DLS Server
> Additional Information:
> Last Name Bender
> First Name Jochen
¿ Could you give me any ideas in how to implement this ?
Thanks in advance
Jochen Bender wrote:
--
Okay, I'll give it a shot.
Declare your data storage class - something like
TSubItemData = class(TComponent) // *1
private
FValid: Boolean;
FNumber: Integer;
protected
procedure SetNumber(ANumber: Integer);
public
property Valid: Boolean read FValid;
property Number: Integer read FNumber write SetNumber;
end;
*1: Descending from TComponent enables ownership. The objects of this class can
be owned by the ListView. When the ListView is then freed, these objects will be
freed too, no additional work will be necessary.
Now you can add items to you ListView, and associate an object of that class to
each SubItem (this is especially useful when you want to sort your ListView by
column header clicks: if the objects know how they compare to each other, the
ListView can be sorted easily).
var
NewItem: TListItem;
NewData: TSubItemData;
(...)
NewItem := someListView.Items.Add;
NewItem.Caption := 'this is the caption';
// one sub item ...
NewData := TSubItemData.Create(someListView);
NewData.Number := 42;
NewItem.SubItems.AddObject('SubItem #1', NewData);
// ... and one more
NewData := TSubItemData.Create(someListView);
NewData.Number := 4711;
NewItem.SubItems.AddObject('SubItem #2', NewData);
Now you can access the data when you use the pointer of every StringList-Item and
typecast it to the class that you associated with it.
'someListView.Items[0].SubItems[0].Data' returns the pointer of the first Item,
first SubItem column (look up help for details) - and you can access it like
this:
theNumber := TSubItemData(someListView.Items[0].SubItems[0].Data).Number;
Have a look at the Data property of TListItem class as well. Using this, you can
also associate an object reference with every single list item (on a row by row
basis, not column by column as with sub items). See the Data property of
TTreeNode as well - for TreeViews.
var
NewItem: TListItem;
(...)
NewItem := someListView.Items.Add;
NewItem.Caption := 'this is the caption';
NewItem.Data := TSubItemData.Create // *2
TSubItemData(NewItem.Data).Number := 42;
//*2 of course, this class should now be named TListItemData or so...
Pooh, I hope that helps. Sorry if it appears a bit complicated. I did not test
the examples given, but they should work out of experience... =)
- Jochen
Jochen Bender wrote:
> Thanks again, Your help got me out of the hole.
> I have another question now about making a class that create objects from and
> associate them with the SubItems to store information in the object for each
> column.
>
> ¿ Could you give me any ideas in how to implement this ?
>
> Thanks in advance
- Jochen
------------------------------------------------------------------------
Jochen Bender <jochen...@psplus.de>
Senior Developer
PSplus GmbH
Jochen Bender
Senior Developer <jochen...@psplus.de>
PSplus GmbH
Netscape Conference Address
Netscape Conference DLS Server
Additional Information:
Last Name Bender
First Name Jochen
Version 2.1