Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Sorting listview tasks based on priority

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
Ben_iti
Asked:
Ben_iti
1 Solution
 
fvaCommented:
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
 
gemartiCommented:
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
 
Ben_itiAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now