![]() |
|
#1
|
|||
|
|||
|
Hello,
I have a listbox with approximately 1000 items. After setting the tabwidth property (listbox columns property remains 0), I populate the listbox like so:- Code:
Listbox1.Items.Add(data1+^I+trim(data2)+^I+data3); It works well and looks good but I have a problem. When I then click on an item in the list, what I want to happen is for all items with the same 'data3' name to be highlighted (selected). Is there an easy way to do this? Thanks. |
|
#2
|
|||
|
|||
|
I scrapped the above idea and used TListview with a vsReport style instead although it would still be nice to know an answer.
I now have a few questions regarding the TListview. 1. To exit the Listview I use OnKeyPress to exit the listview (any key to exit) but get a default beep sound if pressing any key other than space and enter. This doesn't happen with my Listbox and I don't want it here. Any idea? [Q1 SOLVED]. Placing 'key:=chr(0);' at the start of the event sorted the beep. No idea why it was happening though. 2. I would like fixed width columns, a user mustn't be able to change them. Is there a way to do it? 3. I use sort type as stboth but no matter what choice I use, the sorting is not quite spot on when sorting by descending. An example:- Code:
001 300 aaaaaa bbbbbb 002 200 bbbbbb cccccc 003 100 cccccc dddddd Code:
001 300 aaaaaa bbbbbb 004 300 gggggg pppppp 005 300 zzzzzz oooooo 002 200 bbbbbb cccccc 003 100 cccccc dddddd Here's the code:-Code:
procedure TForm1.ListView1ColumnClick(Sender:TObject; Column:TListColumn);
begin
if column.Index=lastsortedcolumn then
ascending:=NOT ascending
else lastsortedcolumn:=column.Index;
ColumnToSort := Column.Index;
listview1.AlphaSort;
end;
procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
var
ix: Integer;
begin
if ColumnToSort = 0 then begin
Compare := CompareText(Item1.Caption,Item2.Caption);
if NOT ascending then compare:=-compare;
end else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
if NOT ascending then compare:=-compare;
end;
end;
Last edited by saxon8; 11-21-2011 at 02:52 AM. |
|
#3
|
|||
|
|||
|
You have to specify which type of sorting you would like to use. IE Numeric/Text/etc..
__________________
"not quite smart enough to be dumb" Extended Stats No Longer Available Due To Changes To The Forum.
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|