Discussions related to Visual Prolog
daveplummermd
VIP Member
Posts: 80
Joined: 18 Jul 2006 17:18

changing a listBox attribute?

Unread post 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
Dave Plummer
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

Re: changing a listBox attribute?

Unread post 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()
Harrison Pratt
VIP Member
Posts: 432
Joined: 5 Nov 2000 0:01

Re: changing a listBox attribute?

Unread post 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).  % <==
daveplummermd
VIP Member
Posts: 80
Joined: 18 Jul 2006 17:18

Re: changing a listBox attribute?

Unread post 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
Dave Plummer
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: changing a listBox attribute?

Unread post 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.
Regards Thomas Linder Puls
PDC
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

Re: changing a listBox attribute?

Unread post 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).
Post Reply