Skip to content
⌘ NSIS Forum Archive

Sorting a DropList

11 posts

ashu.joshi#

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#
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#
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#
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?
Yathosho#
Originally Posted by Wizou View Post
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#
I thought I had this added to the nsDialogs pages somewhere already, but I guess not.. Stuffed it into the FAQ.


( pages are slow to load again - try again later if it doesn't appear to go anywhere )
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.

Stu
Animaether#
Originally Posted by Afrow UK View Post
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...

!include "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