Solved

Sorting listview tasks based on priority

Posted on 2001-08-14
3
256 Views
Last Modified: 2010-04-06
Hello there

Ive got a listview which has a column marked 'priority'.
Listview.items. doesnt have a sort item provided
so I can sort tasks based on say column 3 which is marked 'priority'

I want to sort my tasks in the listview based on the priority in column 3.

Anyone knows hows its done?

Ben Iti
0
Comment
Question by:Ben_iti
3 Comments
 
LVL 4

Expert Comment

by:fva
ID: 6383646
You will have to go for custom sorting.
Basically you define a callback compare function that will compare two items on their third subitem and configure the TListView to use that.
Take a look at CustomSort method of the TListView and at the OnCompare event of TListView

If you need more details, please say.

F.
0
 
LVL 21

Accepted Solution

by:
gemarti earned 24 total points
ID: 6385247
From help:

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;
0
 

Author Comment

by:Ben_iti
ID: 6403174
Wow, you's a clever programmers, Why cant I be like you's?
What am I missing that you's have?

How did you get this knowledge?

I always have to ask questions.

I havent tried it yet but I will soon
Thanks

Ben
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now