Hello
I would like to delete an item by specifying the name.
Example:
sub Cmbx_Remove
dim oSheet, oCmbxSearch, oDoc, oDocCtl, oCtlView As Object
dim iItems, iCycle as integer
dim sStr as string
oSheet = ThisComponent.CurrentController.ActiveSheet
oCmbxSearch = oSheet.DrawPage.Forms.GetByName("Form").GetByName("CmbxSearch")
oDoc = ThisComponent
oDocCtl = oDoc.getCurrentController()
oCtlView = oDocCtl.GetControl(oCmbxSearch)
iItems = oCmbxSearch.ItemCount
For iCycle = 0 to iItems - 1
sStr = oCmbxSearch.GetItem(0)
if sStr = "James" then
oCmbxSearch.removeItem(0, iCycle)
end if
Next
end sub
Cerco e cancello solo “James”
But what I would like to do, is to use a combo box that loads the names present in a column of calc.
Problem:
When I add a name or delete it from the calc column, the combo box does not update.
Solution:
By clicking on the “update” button the macro sub Cmbx_Update does:
- delete all items;
- Add all the names in column B to the combo box.
I tried to link the combo box to column B using the “source cells area” property, but it also loads empty strings “”
sub Cmbx_Update
'************************************************************************
'** adds items to combo box
dim oSheet, oCmbxSearch As Object
dim iItems, iCycle as integer
dim sStr as string
oSheet = ThisComponent.CurrentController.ActiveSheet
oCmbxSearch = oSheet.DrawPage.Forms.GetByName("Form").GetByName("CmbxSearch")
oCmbxSearch.removeAllItems()
'************************************************************************
'** adds items to combo box
dim oRange, oCell As Object
dim iRow, iColumns as integer
Dim AddItem as string
oRange = oSheet.getCellRangebyName("B10:B50")
iColumns = oRange.Columns.getCount() - 1
For iRow = 0 To oRange.Rows.getCount() - 1
oCell = oRange.getCellByPosition(iColumns, iRow)
If oCell.String <> "" Then
if iRow = 0 then oCmbxSearch.text = oCell.String
AddItem = oCell.String
oCmbxSearch.insertItemText(oCmbxSearch.ItemCount, AddItem)
end if
next
end sub
So I have no idea how to do it.
Is there a better way than what I am doing?
I attach the file
ComboBox_Controls_09_100821.ods (13.2 KB)