Solved

Sorting listview tasks based on priority

Posted on 2001-08-14
3
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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