Combobox, Style 1: set value; remove selection on focus

Started by Peter2, February 24, 2016, 06:34:57 AM

Previous topic - Next topic

Peter2

Hi

I`m searching two answers of maybe simple questions:

a) I have a Combobox which is feeded via a list. But is it possible to set the default value in the edit field independent from the list?
(setq list ("A" "B" "C"))
-> display list in Combox
-> set default value to "hello"

b) If I set the focus to the list, the entire value is "selected". If I press "Backspace", the entire value will be deleted.
Is it possible to set the focus to the field, but then release the selection? Then the cursor should be blinking at the end of the string, and "Backspace" delets only the last character of the string

Thanks and regards
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

#1
Yes to both questions. Set the Text property and use SetEditSel to clear the selection and set the caret to the end of the string.

Edit: Actually, a style 1 combo has no edit box, so your question doesn't make sense. Did you mean style 0?

Peter2

But I have Style 1 - see screencast here: http://autode.sk/1QyMJFr
But trying to use
Code (autolisp) Select
(dcl-Control-SetProperty attrib_fill_dia_var_eingabe_comb_inh_dyn "Text" "123")
results in an error: "Argument 0 - value Nil is not allowed"
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

Sorry, I mixed up style 1 and style 2. Style 1 should work fine.

> value Nil is not allowed

I suppose it's either a mistyped symbol name or the form is not active at the time.

Peter2

Quote from: owenwengerd on February 24, 2016, 01:30:37 PM
...or the form is not active at the time.
I tried it in"oninitialize", and that's maybe too soon ...
Will test tomorrow.

Thanks Owen!
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

Quote from: Peter2 on February 24, 2016, 01:35:06 PM
I tried it in"oninitialize", and that's maybe too soon ...

It should work in OnInitialize, so check your symbol name.

Peter2

Hi Owen

the writing of the text to the edit field is OK now - I don't know what I messed up yesterday.

But I can not use SetEditSel in the right way. Here is the code - the first routine only calls the dialogue with "dcl_Form_Show". The second routine reads some values and writes them to labels and to the list and sets the focus - everything is fine, but nothing happens with SetEdit Sel.

I tried some combinations: -1 0 / -1 10 / -1 nil / -1.0 0.0 / 1 2 /, but either everything was selected or I got an error.

Code (autolisp) Select
(defun attf_dynamisch_dialog ( / )
    (setq attf_result (dcl_Form_Show attrib_fill_dia_var_eingabe))

    ; ESC gibt immer Wert 2 zurück
    (if (= attf_result 2)
        (progn
            (princ "\nDas Programm wurde durch den Anwender abgebrochen.")
            (exit)
        )
    )
    (princ)
)


(defun c:attrib_fill_dia_var_eingabe_OnInitialize ( / )
    (dcl_Control_SetCaption attrib_fill_dia_var_eingabe_lbl_attrib_def_inhalt (cdr (assoc 2 attf_elliste)))
    (dcl_Control_SetCaption attrib_fill_dia_var_eingabe_lbl_attrib_inh_inhalt (cdr (assoc 1 attf_elliste)))

    (if (= (strcase attribtext) "[???]")
        (dcl_Control_SetCaption attrib_fill_dia_var_eingabe_lbl_attrib_typ_inhalt "eine Abfrage pro Block ")
        (dcl_Control_SetCaption attrib_fill_dia_var_eingabe_lbl_attrib_typ_inhalt "eine Abfrage pro Durchlauf")
    )
    (if attf_eingabeliste
        (dcl_Control_SetList attrib_fill_dia_var_eingabe_comb_inh_dyn (append attf_eingabeliste attf_musterliste))
        (dcl_Control_SetList attrib_fill_dia_var_eingabe_comb_inh_dyn attf_musterliste)
    )
    (dcl_Control_SetProperty attrib_fill_dia_var_eingabe_comb_inh_dyn "Text" (cdr (assoc 1 attf_elliste)))
    (dcl_ComboBox_SetEditSel attrib_fill_dia_var_eingabe_comb_inh_dyn -1 0)
    (princ)
)
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

I suspect you're getting tripped up by a focus change. After playing a bit, I can see that setting focus to a combo automatically selects everything in the edit field. Therefore it would be pointless to change the edit selection unless the combo box _already has focus_, otherwise the selection will be wiped out anyway once focus is set to the combo box.

If my theory is correct, it will be useless then to set the edit selection during OnInitialize because setting focus to the first control happens after OnInitialize returns.

You could try in OnInitialize to first set focus to the combo (using SetFocus), then set the edit selection immediately after, just in case this makes the final SetFocus not wipe out the selection. Another idea is to ensure that the combo box is the first control on the form (so it receives initial focus), then from OnInitialize call DelayedInvoke to set edit selection after initialization has completed.

In any case, to set the caret at the end of the text with nothing selected, SetEditSel parameters should both be the text length.

Peter2

Quote from: owenwengerd on February 25, 2016, 06:10:13 AM
... then from OnInitialize call DelayedInvoke to set edit selection after initialization has completed....
Hmmm - the delayed-function starts when the called dialogue is closed - too late.

Quote from: owenwengerd on February 25, 2016, 06:10:13 AM
In any case, to set the caret at the end of the text with nothing selected, SetEditSel parameters should both be the text length.
So this is different from the help file which describes a solution with "-1" for "all or nothing" (but I didn't understand this sentence in help ..)
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

Quote from: Peter2 on February 25, 2016, 08:59:54 AM
Hmmm - the delayed-function starts when the called dialogue is closed - too late.

Ok, in that case you can use the Timer event.

Quote from: Peter2 on February 25, 2016, 08:59:54 AM
So this is different from the help file which describes a solution with "-1" for "all or nothing" (but I didn't understand this sentence in help ..)

I guess selecting "nothing" means the caret position doesn't change, but since you specifically want the caret at the end, I think you have to specify the position explicitly.