- NSIS Discussion
- Sorting a DropList
Archive: Sorting a DropList
ashu.joshi
13th November 2006 13:37 UTC
Sorting a DropList
Dear All ,
I have been using NSIS for quite some time now and i really find it very useful and interesting.
Till date all of my queries were answered by seraching through this elaborate Forum of yours. But now i have a query for which i could not find any answers.
I have created a DropList by using "SendMessage $R3 ${CB_ADDSTRING} 0 "STR:Item1" in a loop.
But after adding the items i am unable to sort this list.
Pls advise.
I am using NSIS 2.15 with InstalloptionsEx
Thanks in advance
- Ashutosh
kichik
14th November 2006 23:43 UTC
You can set the CBS_SORT style of the combo box. You could do it by calling SetWindowLong with the System plug-in. If that doesn't work, you'll have to create the window with that style in advance. For that, you'd probably have to change the source code of InstallOptionsEx.
ashu.joshi
15th November 2006 04:58 UTC
Thank you so much. Will try it out and let you know the outcome.
- Ashutosh
ashu.joshi
15th November 2006 09:22 UTC
Hello Kichik,
Tried using the system plugin with the function mentioned by you, but it does not seem to work. This is what I tried :
strlen $5 $NEWLIST
intop $5 $5 - 1
${For} $R1 0 $5
strcmp $R1 0 0 +2
SendMessage $R3 ${CB_ADDSTRING} "STR:None"
strcpy $R2 $NEWLIST 1 $R1
strcmp $R2 "|" +2
SendMessage $R3 ${CB_ADDSTRING} 0 "STR:$R2"
${next}
SendMessage $R3 ${CB_SETCURSEL} 0 0
;SetWindowLong(hwnd,GWL_STYLE,0)
;!define GWL_STYLE -16
;!define GWL_EXSTYLE -20
strcpy $1 68288533 ;"0x2000L" ;"CBS_SORT"
System::Call "user32::SetWindowLongA(i $R3, i ${GWL_STYLE}, i r1)"
-----------------------------------------------------------
So i just sorted my string before using the CB_ADDSTRING and that solved the problem.
Thanks you.
-Ashutosh
Yathosho
12th April 2010 16:34 UTC
looking for the same. i'm using the locate plugin to get a couple of files i want to display in a droplist. looking for some way to sort the files alphabetically.
any ideas?
Wizou
12th April 2010 17:33 UTC
try setting the CBS_SORT style *before* adding the strings
Yathosho
12th April 2010 18:05 UTC
Originally posted by Wizou
try setting the CBS_SORT style *before* adding the strings
it won't display the control.
i guess i could use the array plugin, but why should it - if it should work without it
Animaether
12th April 2010 18:49 UTC
I thought I had this added to the nsDialogs pages somewhere already, but I guess not.. Stuffed it into the FAQ.
http://nsis.sourceforge.net/NsDialog...oplist_control
( pages are slow to load again - try again later if it doesn't appear to go anywhere )
Yathosho
12th April 2010 21:32 UTC
thanks animaether, works perfectly
Afrow UK
12th April 2010 23:10 UTC
For the record you have to get the current style first with GetWindowLong, binary or CBS_SORT with the returned value and set the new value with SetWindowLong.
Stu
Animaether
12th April 2010 23:47 UTC
Originally posted by Afrow UK
For the record you have to get the current style first with GetWindowLong, binary or CBS_SORT with the returned value and set the new value with SetWindowLong.
I couldn't get that to work when I made that header.. maybe I missed something, though...
"LogicLib.nsh"
>!include "nsDialogs.nsh"
>!include "WinMessages.nsh"
>/* from: http://nsis.sourceforge.net/NsDialogs_FAQ#How_to_create_a_sorted_droplist_control */
>!include "nsDialogs_createDroplistSorted.nsh"
>OutFile test.exe
XPStyle on
>Var dialog
>Var hwnd
>Var null
Page custom nsDialogsPage
>Function nsDialogsPage
nsDialogs
::Create 1018
Pop $dialog
${NSD_CreateDroplist} 0 0 100% 40% ""
Pop $hwnd
System::Call "user32::GetWindowLong(i $hwnd,i ${GWL_STYLE}) i.r1"
IntOp $1 $1 | ${CBS_SORT}
System::Call "user32::SetWindowLong(i $hwnd,i ${GWL_STYLE}, i r1)"
${NSD_CB_AddString} $hwnd "C"
${NSD_CB_AddString} $hwnd "B"
${NSD_CB_AddString} $hwnd "A"
/* doesn't work? */
${NSD_CreateDroplistSorted} 0 20% 100% 40% ""
Pop $hwnd
${NSD_CB_AddString} $hwnd "Z"
${NSD_CB_AddString} $hwnd "Y"
${NSD_CB_AddString} $hwnd "X"
/* should work */
nsDialogs::Show
FunctionEnd
Section
SectionEnd
>