I have a ListBox populated with file names read from a directory folder. Does anyone know of a way to added a button/s that will sort the ListBox in ascending or descending order? If not, it may be something to look at adding to future ListBox Settings.
Sort ListBox (Ascending / Descending)?
Collapse
X
-
My suggestion would be to read the contents of the listbox into a table and then use the Table.Sort action to sort the table as appropriate and then rewrite the table back into the listbox. the help file gives a function on reverse sort as well.TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
-
-
Originally posted by mafranksTigger, I did as you suggested. Works great but one needs to remember to uncheck the 'sort' in the ListBox settings as it will take precedence over any reverse sort code the is written. Thanks for your suggestion.
Would you be willing/able to post your code/functions for others benefit?
TiggTJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
Comment
-
-
This is one page of many that make up an e-Safety Manual for use throughout our manufacturing plant. On this page the user is presented with a list of minutes from a safety committee. The minutes are kept on the company's networked drive. The file names for the minutes are always in the format: 'yyyy-mm-dd'. Therefore when a reverse (descending) sort is executed prior to filling the ListBox, the minutes show the latest first so the viewer does not have to scroll down several years worth of monthly meeting minutes to get the latest minutes.
For the descending sort to work, the Sort checkbox in the ListBox settings must be unchecked. If you wanted to do an ascending sort, simply check the Sort checkbox and don't wory about any addtional coding. I suppose sort buttons could be added to the page if you wanted to sort either way.
I cannot take credit for all of this code. Much of it was suggestions from the members of AMS Forums. Thanks everybody. Soooo for the code:
--Find files on Network Drive for PSRB Committee
files = File.Find("\\\\usldcvs1fsh02\\lnlccf20$\\SAFETY\\S afety Committees\\Minutes of All Safety Committees\\PSRB", "*.*", false, false, nil);
if files ~= nil then
min = 1;
max = Table.Count(files);
ListBox.DeleteItem("ListBox1", LB_ALLITEMS)
-- Sort files by decending order
function sorter(v1,v2)
if (v1 > v2)then
return true;
else
return false;
end
end
--Sort files and add to ListBox
Table.Sort(files, sorter);
for count = min, max do -- count will increase from 1 to the number of files
split = String.SplitPath(files[count]); -- split is a variable that will hold the current 'files' path
result = ListBox.AddItem("ListBox1", split.Filename..split.Extension, files[count]); -- and at the same time the current 'index' and 'data' elements will be added into the ListBox object.
end
--Do this if no files are found in folder
else
Dialog.Message("Alert!", "File(s) not found!");
ListBox.SetEnabled("ListBox1", false);
end
Comment
-
-
Great Thanks. Always nice to see how things ended in a post.
TiggTJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
Comment
-
-
DataGrid be good.
You could always use functions found on this site to convert the Gregorian date to Julian and sort using a julian date and then convert back to Gregorian and put back into the LB.
Just a thought.TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
Comment
-
-
Switched to ISO
Ok, so I've switched the date to ISO but is still not sorting in descending order. It sorts but ascending...such as
1998/08/02
2005/05/15
2005/08/28
2005/10/30
My code is:
tpog2site = SQLite.QueryToTable (db2, "Select * from "..srcdb.." where SITE ="..answer);
function sorter(v1,v2)
if (v1 > v2)then
return true;
else
return false;
end
end
Table.Sort(tpog2site, sorter);
Could it possibly be the code that populates the Listbox..
for b = 1, tpog2site.Rows do
ListBox.AddItem ("ListBox1", tpog2site.Data[b]["LASTPUBLISHEDDATE"].."\t"..tpog2site.Data[b]["S_POG_NAME"].."\t"..tpog2site.Data[b]["BASE_POG_NAME"].."\t"..tpog2site.Data[b]["POG_CODE_DESC_ENG"], tpog2site.Data[b]["POG_CODE_DESC_ENG"]);
end
Any way of doing it without the plugin????
Comment
-
-
Run the for loop in reverse
Code:for b = tpog2site.Rows, 1, -1 do ListBox.AddItem ("ListBox1", tpog2site.Data[b]["LASTPUBLISHEDDATE"].."\t"..tpog2site.Data[b]["S_POG_NAME"].."\t"..tpog2site.Data[b]["BASE_POG_NAME"].."\t"..tpog2site.Data[b]["POG_CODE_DESC_ENG"], tpog2site.Data[b]["POG_CODE_DESC_ENG"]); end
Last edited by Worm; 10-26-2005, 01:07 PM.
Comment
-
Comment