Solved

Sorting listview tasks based on priority

Posted on 2001-08-14
3
252 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

19 Experts available now in Live!

Get 1:1 Help Now