Create an event for Combo Box

hello everyone
I created a combo box, but if I click on an item in the list, no event is triggered.
How do you create an event that triggers when the value of the Item changes?
My example:

REM  *****  BASIC  *****
sub Search_Name
Dim oSheet, oCell, oCmbxSearch as object
Dim sValue as string
oSheet = ThisComponent.GetSheets().GetByName("Foglio1")
oCell = oSheet.getCellByPosition(0, 0)
oCmbxSearch = oSheet.DrawPage.Forms.GetByName("Formulario").GetByName("CmbxSearch")
sValue = oCmbxSearch.GetCurrentValue()
oCell.string = sValue	
end sub

Hello everybody

Sorry for my english which is translated by google translate

I answer my question with another account. I can no longer log in with Loki 6659.

There are many ways to add events to a combo box.

In the example below I add the Status changed event to the CmbxSearch combo box

In design mode:

  1. right click on the combo box;

  2. select Control properties;

  3. from the events tab select Status changed;

  4. choose the macro.

Write a macro that does something.

Example:

Search in column B for the item selected in the combo box:

'FIND THE ITEM SELECTED FROM THE COMBO BOX
sub Search_Name
Dim oSheet, oForm, oRange, oCmbxSearch, oDocument, oDispatcher, oCell as Object
Dim oConv as object
Dim sSearch as string
Dim iRow, jColumns as Integer
'OSheet = the active page
oSheet = ThisComponent.CurrentController.ActiveSheet
'oForm = the form of the “Form” sheet
oForm = oSheet.getDrawPage().getForms().getByName(“Form”)
oRange = oSheet.getCellRangebyName(“B10:B50”)
’ oCmbxSearch = CmbxSearch
oCmbxSearch = oSheet.DrawPage.Forms.GetByName(“Form”).GetByName(“CmbxSearch”)
oDocument = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
sSearch = oCmbxSearch.text
jColumns = oRange.Columns.getCount() - 1
'cycles from cell B10 to cell B50
For iRow = 0 To oRange.Rows.getCount() - 1
oCell = oRange.getCellByPosition(jColumns, iRow)
If oCell.String = sSearch Then
oConv = ThisComponent.createInstance(“com.sun.star.table.CellAddressConversion”)
oConv.Address = oCell.getCellAddress
sSearch = oConv.UserInterfaceRepresentation
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = “ToPoint”
args2(0).Value = sSearch
oDispatcher.executeDispatch(oDocument, “.uno:GoToCell”, “”, 0, args2())
exit for
end if
Next
end sub

I don’t know how to attach the calc file with macros, it would have been useful

Item Status Changed will occur if an item is newly selected from the list. It will neither be thrown if the already selected unedited item is selected anew, nor if only the current entry is edited.

Text modified is thrown if the current entry is edited or replaced by a different selection.

Everything only can work if edit mode for the form is off.

If the ComboBox has a linked cell any changes caused by editing that cell don’t throw a control event for me.

It’s true, I don’t have a linked cell.
The example I wrote only serves to find the cell of a sheet (column B in the example) that has the same value as the selected item.
It is similar to the find function or the automatic filters of Calc.

I still don’t clearly understand what’s.the actual question.
You now seem to know how to bind a Sub to a FormControl event.

@Loki2323 wrote; I don’t know how to attach the calc file with macros,

It will often be advisable to include event handlers (if needed at all) with the document. Do you need a guide how to create a Basic module located in the document?

Throw a glance on the attached example. It also contains a solution for your example task with a formula using a linked cell.
To write the included code for the first solution (with FormControl events) may have taken more than an hour.
The second solution was a matter of a minute.

demoComboBoxEventsAndAlternativeSolution.ods (14.5 KB)

The problem with making myself understood is that I don’t know English well
and I translate everything with a translator
Request:
I still don’t clearly understand what’s.the actual question.
You now seem to know how to bind a Sub to a FormControl event.

Reply:
Yes, I know how to bind a Sub to a FormControl event.

Request:
wrote; I don’t know how to attach the calc file with macros,

Reply:
Yes, my application was poorly written
I would like to attach the Calc file, as you did with “demoComboBoxEventsAndAlternativeSolution.ods”.
I don’t know how to attach a file on Ask LibreOffice.

Thanks for the attachment, very useful for beginners like me

Why can’t I attach files on ask.libreoffice.org?

When you are editing a post you are using an “editing frame”.
On top of this frame you find an icon bar offering different services. In my case it shows 13 icons of which the seventh consists of a “base” and an upward arrow. This is the icon for the upload tool. Having activated it, you should find an option “From my device” …
If the icon isn’t shown for you or is disabled, the current settings of “discourse” software may only allow uploading for users having qualified by some upvotes. I don’t know exactly.
Please tell if you can’t use the mentioned tool.

Why didn’t my uploaded example help you?

1 Like

it is true there is the load icon
Thank you