Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2011, 11:08 AM
saxon8 saxon8 is offline
Junior Member
 
Join Date: Nov 2011
Posts: 2
Default Extract data from field in multi column listbox

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.
Reply With Quote
  #2  
Old 11-20-2011, 02:36 PM
saxon8 saxon8 is offline
Junior Member
 
Join Date: Nov 2011
Posts: 2
Default

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
No problem above but reverse sorting the second column...
Code:
001      300        aaaaaa     bbbbbb
004      300        gggggg     pppppp
005      300        zzzzzz     oooooo
002      200        bbbbbb     cccccc
003      100        cccccc     dddddd
I would've expected the 3rd column to be zzzzzz,gggggg,aaaaaa rather than aaaaaa,gggggg,zzzzzz 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;
Thanks.

Last edited by saxon8; 11-21-2011 at 02:52 AM.
Reply With Quote
  #3  
Old 08-10-2012, 07:45 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:34 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.