Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort files in TListBox by file extension

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
As above, how would I do this? I have one idea but it
isn't very clean.

1. Turn Sorted off.
2. Loop through all files in the listbox getting their
extension and put it infront of the same file
3. Turn it on and off again.
4. Loop through to remove all extensions again.

It'll work but it's crap programming, does anyone have any better ideas?

[bobafett] BobbaFet [bobafett]

Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
faq102-5352
 
I am not sure that you can do this but can you use the listview component separate the extensions out into another column and sort on that column?

Steve: Delphi a feersum engin indeed.
 
Does anyone know how to use the column feature in TListBox?
I was reading the helpfile about it but it doesnt actually
say how you can use the additional columns :S

[bobafett] BobbaFet [bobafett]

Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
faq102-5352
 
Columns in a ListBox are used to switch form vertical scrolling to horizontal scrolling and are populated automatically if the Columns property is set appropriately.

As such sggaunt's suggestion is probably the best way forward.

Hope this helps.

[vampire][bat]
 
Bobbafet
AFAIK the extra cols just wrap around the data. They are NOT another set of values at the same indexes.
In other words when 1 col is full the next items index is at the top of col 2 etc.
and the box will raise the value of col count to fit in your data.



Steve: Delphi a feersum engin indeed.
 
Oh ok, I didn't get that from the helpfile. Well, I guess I'll just have to drop this idea then. It would be too much of a work around to go changing to a listview, I just thought it would be a nice idea.

[bobafett] BobbaFet [bobafett]

Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
faq102-5352
 
But thank you for your input anyway!

[bobafett] BobbaFet [bobafett]

Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
faq102-5352
 
Ta Bobbafet
I was almost right I had to Load D3 to get the correct answer, as D7 gives the help on the more advanced list box and not the standard one.
Col count is the number of cols that will be displayed without a horz scroll bar.


Steve: Delphi a feersum engin indeed.
 

BobbaFet, I wouldn't call this any more elegant, but another possibility is to create a TStringList, assign the Items from the list box, then use the CustomSort method of the TStringList to sort it the way you want, then assign the sorted TStrings back to the list box.

Not sure, but I think the CustomSort method was added in D7.

 
Custom sort is available in D5.

You should also consider using a TListView (also available in D5). It has a CustomSort method that you can use (without shoshing through a TStringList) and can show your files in columns in a way similar to a Detail File view in a Windows explorer view.

(Hint: set ViewStyle to vsReport)

I would probably use TListView. That allows the user to click on the column heading to control which sub-field he/she wants to sort on. (Of course, you still have to provide the code to handle the event, using Custom Sort.)



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top