Archive: ListBox and selected value


ListBox and selected value
  Hello all,
I've been dabbling with NSIS for a bit now, and have a couple of decent installers working.

However this last one is really confusing me! I have a ListBox on a page, that I populate then need to retrieve the value on the subsequent page. I cannot see to figure out the right query, as tried many, those from forums, etc and don't seem to get it right!

    nsDialogs::Create /NOUNLOAD 1018

Pop$0

${NSD_CreateText} 0 47 30% 12u 200
Pop $EDIT
>${NSD_CreateListBox} 0 87 40% 32u ""
Pop $huntgroup
SendMessage $huntgroup${LB_ADDSTRING} 0 "STR:entry1"
SendMessage $huntgroup ${LB_ADDSTRING} 0 "STR:entry2"
SendMessage $huntgroup ${LB_ADDSTRING} 0 "STR:entry3"

${NSD_CreateLabel} 0 10u 75% 40u "Select your hunt group from the drop down menu"
Pop $0


${NSD_GetText} $EDIT $myvar1

SendMessage $huntgroup${LB_GETSEL} 0 0 $huntgroup
>
I have tried several different ways of getting the value and all either return 0 or return a 4 or 5 digit number (hwid perhaps?)

Thanks in advance for anyone who can help!

SendMessage $huntgroup ${LB_GETSEL} 0 0 $0
System::Call user32::SendMessage(i$huntgroup,i${LB_GETTEXT},ir0,t.r0)
MessageBox MB_OK $0

LB_GETSEL
  I don't understand it. I've tried kichik's tip and it didn't work. Sorry, but I'll post whole script. The messagebox shows empty value.


nsh


Name "NSD: Listbox"
>OutFile "listbox.exe"

>Page custom nsDialogsPage
Page custom validate
Page instfiles

>Var LISTBOX_1

>Function nsDialogsPage
nsDialogs
::Create /NOUNLOAD 1018
Pop$0
${NSD_CreateListBox} 200 35 20% 12u ""
Pop $LISTBOX_1
SendMessage $LISTBOX_1${LB_ADDSTRING} 0 "STR:0"
SendMessage $LISTBOX_1 ${LB_ADDSTRING} 0 "STR:1"
SendMessage $LISTBOX_1 ${LB_ADDSTRING} 0 "STR:2"
SendMessage $LISTBOX_1 ${LB_ADDSTRING} 0 "STR:3"
nsDialogs::Show
FunctionEnd

>Function Validate
SendMessage $LISTBOX_1${LB_GETSEL} 0 0 $1
System::Call user32::SendMessage(i$LISTBOX_1,i${LB_GETTEXT},ir1,t.r1)
MessageBox MB_OK $1
FunctionEnd

Section
SectionEnd
>
I also tried the LB_GETCURSEL message but it returns '0'. Where is the problem and how does it work?

The page, including the list box, is destroyed by the time the validate function is called. You must use that code in the leave callback function of the page.

Page custom nsDialogsPage validate
You also need to replace LB_GETSEL with LB_GETCURSEL.

Thank you very much!


And how can I create ComboBox? I tried to change ${NSD_CreateListBox} -> ${NSD_CreateComboBox} and rename all messages LB_ -> CB_, but combobox is empty. Is there something special to do when creating combobox?


That's probably because the combo is too short to display the selection and can only display the text field. Try 50u instead of 12u.


Aaah, I see! Actually, I am interested in "Drop-down list" :-) Is it possible to mix listboxes and dropdown lists on one page?


I have combobox with dropdown list style, but I had to edit nsDialogs.nsh and add |${CBS_DROPDOWNLIST} at the end of !define __NSD_ComboBox_STYLE. Can I change (combobox control) style from script, not from .nsh file?


And another question - is there any difference when sending "gettext" message to listbox or combobox? I have combobox and all CB_GETTEXT, LB_GETTEXT and CB_GETLBTEXT return empty value.


validatePage 

SendMessage $CB_kontrola${CB_GETCURSEL} 0 0 $kontrola ### index is OK
System::Call user32::SendMessage(i$CB_kontrola,i${CB_GETLBTEXT},i$kontrola,t.$1)
messagebox mb_ok "$kontrola $1"
System::Call
FunctionEnd
>

Currently, you can only call nsDialogs::CreateItem manually to add extra styles to the defaults defined in nsDialogs.nsh.

The problem with your text retrieval mechanism is that you pass $1 instead of r1. $1 is translated to the actual value of $1 and so the System plug-in doesn't know it needs to write something into $1.


Sorry kichik, I tried $r1 and it is still empty. :confused:
My code is below:


SendMessage $CB_kontrola ${CB_GETCURSEL} 0 0 $kontrola ### index OK

>System::Call user32::SendMessage(i$CB_kontrola,i${CB_GETLBTEXT},i$kontrola,t.$r1)
>messagebox mb_ok "$kontrola $r1"

r1, not $r1.


THANKS! :up:


please show us the correct codes for your listbox and combobox page