Page 1 of 1
changing a listBox attribute?
Posted: 5 Apr 2022 21:42
by daveplummermd
Hello
Is it possible to change attributes of a ListBox programmatically. for example I have a dlg with a Listbox
where multiselect is set to "true" in the properties box, and then in the program, I am unsuccessfully trying to change it with this code:
Code: Select all
mysetMultiSelect(Boolean) :-
listbox_ctl:setMultiSelect(Boolean).
On debug, is successfully steps through the code, but behavior does not change.
What do you think?
Thanks in advance
Dave
Re: changing a listBox attribute?
Posted: 6 Apr 2022 20:55
by Gukalov
Code: Select all
interface listBox
%.............
%.............
%.............
predicates
setMultiSelect : (boolean MultiSelectIsSet).
% @short Specifies whether the list box allows multiple selections.
% @exception gui_exception::unableToSetPropertyAfterShow_exception
% @end
I have no idea what is going on with the exception, but in every case:
Unable To Set Property After Show.
May be you should create two listBox - one multiSelect one not.
Both have the same event listener.
And switch them on your properties box value changes
currentListBox := if true = bla-bla-bla then.... else... end if,
currentListBox:bringToTop()
Re: changing a listBox attribute?
Posted: 7 Apr 2022 2:35
by Harrison Pratt
I deal with this issue by using two different constructors for the dialog, one for multiple selection and another for single selection. For example:
Code: Select all
newMulti(Parent) :-
dialog::new(Parent),
generatedInitialize(),
listbox_ctl:addList(["one", "two", "three"]),
listbox_ctl:setMultiSelect(true). % <==
or
Code: Select all
newSingle(Parent) :-
dialog::new(Parent),
generatedInitialize(),
listbox_ctl:addList(["one", "two", "three"]),
listbox_ctl:setMultiSelect(false). % <==
Re: changing a listBox attribute?
Posted: 8 Apr 2022 0:31
by daveplummermd
Thanks for the responses.
The double constructor method is exactly what I had done, I just thought there should be a more elegant way.
Thanks
Re: changing a listBox attribute?
Posted: 8 Apr 2022 8:21
by Thomas Linder Puls
I have not looked into this, but I believe the behavior follows from a style flag which is set when the actual Windows control is created.
In our context it means that the flag must be set before the control is
shown, i.e. before the dialog is
shown.
There are many ways to set the flag between
generatedInitialize and the
show; doing it in the constructor is an obvious way. But I would avoid the duplication of code:
Code: Select all
clauses
new(Parent, MultiSelect) :-
dialog::new(Parent),
generatedInitialize(),
listbox_ctl:addList(["one", "two", "three"]),
listbox_ctl:setMultiSelect(MultiSelect). % <==
Whether or not to have additional constructors without the extra argument is a matter of taste and convenience.
Re: changing a listBox attribute?
Posted: 11 Apr 2022 16:10
by Gukalov
daveplummermd wrote: ↑5 Apr 2022 21:42
...for example I have a dlg with a Listbox
where multiselect is set to "true" in the properties box...
Impossible to change multi-properti after show, but possible to switch listBoxes:
Code: Select all
implement main
open core
clauses
run() :-
Dlg = dialog::new(window::getActiveWindow()),
Dlg:setFont(vpi::fontCreateByName("Verdana", 22)),
Dlg:setUnit(dialog::pixelUnit),
Dlg:setModal(true),
Dlg:setDecoration(frameDecoration::titlebar([frameDecoration::closeButton])),
Dlg:setPosition(400, 100),
Dlg:setSize(300, 200),
CheckB = checkButton::new(Dlg),
CheckB:setPosition(50, 160),
CheckB:setSize(100, 300),
CheckB:setText("Multi"),
ListenerLB = {(LBx) :- console::write(LBx:getSelectedItems(), "\n")},
CreateLB = {(Multi) = LB :-
LB = listBox::new(Dlg),
LB:setSize(300, 150),
LB:addList(["1", "2", "3", "4"]),
LB:setMultiSelect(Multi),
LB:addSelectionChangedListener(ListenerLB) },
ListBoxSingle = CreateLB(false),
ListBoxMulti = CreateLB(true),
CheckB:addStateChangedListener({(_, _, State) :-
CurrentLB = if checkButton::checked = State then ListBoxMulti else ListBoxSingle end if,
CurrentLB:bringToTop(),
ListenerLB(CurrentLB) }),
% Dlg:postAction({ :- CheckB:setCheckedState(checkButton::checked) }),
Dlg:show().
end implement main
goal
console::runUtf8(main::run).