How to deselect text in Combobox? (Calc, Basic)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sevalav
Posts: 91
Joined: Mon Apr 16, 2012 12:37 am

How to deselect text in Combobox? (Calc, Basic)

Post by sevalav »

Hello,
I have some dialog in Calc, and combobox on this dialog. How to deselect text in combobox? When I click on dropdown list, selected item will be appear in comboboxs "screen". This item is whole in blue colored background, because it is selected. This is problem to me, because this item and other items on dropdown list are now case sensitive to my touch mouse "roller" on my lap top, and without my knowledge I can change seleceted item. Please a little help.
Apache OpenOffice 4.1.0, Win
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: How to deselect text in Combobox? (Calc, Basic)

Post by RPG »

Hello

Maybe you can set a property of the combobox. There is a property hide Selection. Also control^Home seems to work.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: How to deselect text in Combobox? (Calc, Basic)

Post by B Marcelly »

Are you sure you need a ComboBox ?
A Combobox is useful only when you need the facility to enter something else than one of the list items.
If you only need to select one of the items of the list, use a ListBox.

How to unselect all items at opening of the dialog :
  • With a ComboBox : in the IDE, properties, tab "General", property Text : clear this field.
  • With a ListBox : in the IDE, properties, tab "General", property Selection : clear this field.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
sevalav
Posts: 91
Joined: Mon Apr 16, 2012 12:37 am

Re: How to deselect text in Combobox? (Calc, Basic)

Post by sevalav »

Thanks for your replies. I tried to implement suggestions but they do not solved my problems. As I can see, to stopping roller of mause to acting as I described in first post, I must implement some code for mouse event, what is... well, maybe little difficult for me. Second, because I have search results in other textfields based from text in combobox, it is much easier to me to put command .setFocus() in next field in the end of code which serve for searching. When focus is out of combobx the roller could not make a problems. I think this is satisfactory solution for me.
But I still have this question: how to select/deselect text in combobox with code (basic)?
Apache OpenOffice 4.1.0, Win
Tshep
Posts: 3
Joined: Wed Jan 31, 2018 5:15 am

Re: How to deselect text in Combobox? (Calc, Basic)

Post by Tshep »

I have the same problem. The code that I expect to do this would be

Code: Select all

listbox.selectItemPos(-1, true)
, but running this does nothing. Interestingly, if you have a listbox with nothing selected and interrogate the property selectItemPos, it returns -1, which implies that

Code: Select all

selectItemPos(-1,true)
should work. I have also tried

Code: Select all

selectItem("")
which also just does nothing. My suspicion is that this is an oversight on the part of the developers. Certainly in VBA selecting a list position of -1 does the trick.
Openoffice 4.1.5 on Windows 10
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to deselect text in Combobox? (Calc, Basic)

Post by JeJe »

Tshep - have you tried setting the focus to another control? It could be a control that doesn't do anything and is outside the visible area of the dialog so hidden.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to deselect text in Combobox? (Calc, Basic)

Post by Zizi64 »

Tshep, ara you using one of the existing object inspection tools (Xray, MRI)? You can display all of the available properties and methods (and others) by usage of these tools.

Please upload your ODF type sample file here with the embedded macro routine what you tried to create.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Tshep
Posts: 3
Joined: Wed Jan 31, 2018 5:15 am

Re: How to deselect text in Combobox? (Calc, Basic)

Post by Tshep »

Hello Tibor, sorry to have been away so long. I don't use xray or MRI - I've got my own routine that I use to inspect properties and methods. My file is too long to upload, but here's what you can do to replicate the problem. Create a dialog, drop a listbox and button on it. Add a few entries to the listbox list (apples, oranges, apricots, bananas etc). Set the button to run a macro when clicked and add these lines to the macro (say you called it "test"):
sub test(e as event)
'see what itemPos is with no selection at startup, then with an item selected
msgbox (e.Source.Context.getControl("ListBox1").selectedItemPos)
e.Source.Context.getControl("ListBox1").selectItemPos(-1,true)
end sub
What you will see is that at startup, no items selected, itemPos is -1. Go ahead and select an item. You will see it's position as selected. Click the button. Nothing happens. The item remains selected, even if you move the focus to any other control on the dialog. In fact, you can do nothing at all to un-select an item in the box short of restarting the dialog. Logically, setting itemPos to -1 should do this.
- Tshep
Openoffice 4.1.5 on Windows 10
Post Reply