Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sorting listview tasks based on priority

Posted on 2001-08-14
3
Medium Priority
?
273 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 96 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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