Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 11th, 2009, 04:31 PM
Simmo07 Simmo07 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 109 Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 21 h 26 m 40 sec
Reputation Power: 27
Sort TListView when clicking column headers?

Hi, i have a listview with 5 column headers, and obviously subitems added into many rows underneath.

how do i sort the data in the corresponding column when that header is clicked?

for example, open a folder on your computer, view the folder as details and click one of the headers such as Name, Size, Type etc.. - see how it sorts the data?

how can i do that in delhi

Reply With Quote
  #2  
Old June 11th, 2009, 08:47 PM
clivew clivew is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 1,124 clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level)clivew User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 6 Days 1 h 39 m 23 sec
Reputation Power: 272
Its actually in the help file.

Check out the onColumnClick Event and the AlphaSort method.

Reply With Quote
  #3  
Old June 12th, 2009, 04:57 AM
Simmo07 Simmo07 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 109 Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level)Simmo07 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 21 h 26 m 40 sec
Reputation Power: 27
Quote:
This example shows how to use the OnColumnClick and OnCompare events of a list view to let users sort the columns in a report-style list view by clicking on the column headers. This requires a global variable to keep track of the column that was clicked:

var ColumnToSort: Integer;

The OnColumnClick event handler sets the global variable to indicate the column to sort and calls AlphaSort:

procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn);

begin
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
end;


The OnCompare event handler causes the list view to sort on the selected column:

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
var
ix: Integer;
begin
if ColumnToSort = 0 then
Compare := CompareText(Item1.Caption,Item2.Caption)
else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
end;

end;

Note: This OnCompare event handler uses the global CompareText function. An application may want to use AnsiCompareText, CompareStr, or AnsiCompareStr instead, depending on whether the comparison should be case-sensitive and whether the locale should be considered.


i will work with this thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Sort TListView when clicking column headers?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
Stay green...Green IT