Code is as follows:
1: This is what I posted for the alphabetical and somenumerical values in the list that is loaded.
procedure TMainForm.SortListButtonClick(Sender: TObject);
begin
ListView1.SortType := stBoth;
CurrentStatusLabel.caption := 'List Sorted';
end;
I would like to also sort it from z - a... that is the problem atm...
2: Sort a list numerically... tried stdata..
ListView1.SortType := stData;
this does not truly sort numerically...
3: Capitalize the first letter in a list or all first letters in a list... no idea. Not much luck on reading up on it. Most code I saw was applied to other edit boxes and not tlistview.
4: Reversing the order of a line in listview.. Cant get that to work either and looking it up hasn't afforded much help either. I was given this to start off with.
s[ 1 ] := UpCase( s[ 1 ] );
so there you have it.
im new
Thanks for any help...
Squidd, whenever you look up Delphi help - e.g. for
SortType - also make sure that you check out the entries under
See Also.
In this instance what you need is to checkout the
OnCompare. event. You can use this event to alter the way the sort is being done. Here is some, untested, code that should do your reverse sort
procedure TMaster.WhenLVCompare(Sender:TObject;Item1,Item2:TListItem;Data:Integer;var Compare:Integer);
begin
Compare:=CompareText(Item2.Caption,Item1.Caption);
end;
As to the problem with capitalization - remember that you will need to update the corrected entry in the listview. Thus if you have the code
procedure TMaster.InCapLV;
var i:Integer;
s:String;
AList:TListItems;
begin
AList:=lvOne.Items;
with AList do
for i:=0 to Count - 1 do
begin
s:=Item[i].Caption;
s[1]:=UpCase(s[1]);
Item[1].Caption:=s;
end;
end;
you should get the result you desire.
As I have discussed before this is not really the right way to deliver speed nor to write good code. However, I guess that is the learning process you are currently going through.
p.s. - I guess I should have commented on the OnCompare event and the CompareText method
a. By default some Delphi controls, such as ListView, and controls, such as TStringList, know how to do a sort.
b. If you don't like the default sort order the offer - typically A -> Z - you can alter that by writing the OnCompare event.
c. CompareText is a unit in SysUtils - spend some time looking at the routines available in SysUtils. Could save you a lot of time. Here is what Delphi help says regarding CompareText
CompareText compares S1 and S2 and returns 0 if they are equal. If S1 is greater than S2, CompareText returns an integer greater than 0. If S1 is less than S2, CompareText returns an integer less than 0. CompareText is not case sensitive and is not affected by the current locale.
I think you will be able to figure out the rest.