Ecere SDK/eC Forums http://ecere.org/community/ Print view |
|
Dropbox Sort http://ecere.org/community/viewtopic.php?f=5&t=349 |
Page 1 of 1 |
Author: | jerome [ Fri Mar 01, 2013 2:43 pm ] |
Post subject: | Dropbox Sort |
nickdobrinich asks: Hi Nick, Upon creation, elements in a DropBox are automatically sorted in ascending order by the first DataField. When adding an element later, however, that element does not get inserted at the sorted place. This is because usually, drop boxes are used with a fixed list of elements and are sorted before form creation. To sort the contents when adding an element, simply call sort with either 1 for ascending order or -1 for ascending order. By default, a DropBox (like a ListBox) has a single DataField of 'String' data type. Passing null for the 'DataField' to a DropBox method refers to the first field (the default field in this case). Here is an example: Code: Select all
Code: Select all
-Jerome |
Author: | nickdobrinich [ Fri Mar 01, 2013 5:15 pm ] |
Post subject: | Re: Dropbox Sort |
Jerome, Merci for your suggested code. As you stated, dropBox1.Sort(null, 1) worked. I found that I did need this sorting step because when I AddString()ed the out of order strings into the drop box, they were not automatically sorted. Thx. |
Author: | jerome [ Fri Mar 01, 2013 5:28 pm ] |
Post subject: | Re: Dropbox Sort |
Nick, When did you call AddString() ? If you called them in the Form constructor, you should not need it ( they should automatically be sorted in alphabetical order ). Try the first example I provided. -Jerome |
Author: | nickdobrinich [ Sat Mar 02, 2013 12:17 pm ] |
Post subject: | Re: Dropbox Sort |
Ok, I used your code in the 1st example. Should have paid more attention to the dropbox being initialized in the Form() constructor. However, the initial dropdown list is not sorted after the AddString() calls UNTIL the button is clicked to add the newest element. Tested on both Linux and Win XP. This is not a big problem now that I know how to dropBox.Sort() Your 2nd example also addressed more of my problem. I want to present 400 elements in a sorted dropbox list of index, cleanfilename and filepathfilenameext like this after Sort(): 77 ABC /mnt/home/data1/ABC.dat 334 DEF /mnt/home/data7/DEF.dat ... 281 XYZ /mnt/home/data0/XYZ.dat The user doesn't see the file path part. And I can do this with a parallel array and the index from the sorted dropbox. Thank goodness you gave me the capability to use eC code. Oh, and I just discovered that you built in 1st key accelerators to jump around the dropbox list without scrolling. Very nice. |
Author: | jerome [ Sat Mar 02, 2013 5:05 pm ] |
Post subject: | Re: Dropbox Sort |
Hi nick, Really? When I tested the code I pasted everything came up sorted first. Note sure if it's a misunderstanding, or a the behavior of a different version? Note that you can also associate a user-defined data value with each row of the list box, using the Row::tag property. You can then retrieve a row by tag, or retrieve the tag of a specific row. This might be useful to you as well. Regards, Jerome |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |