Is there a way or process to “add a row” to a Combobox! I am referring to after the open event has passed.
Also if there is a plugin that will do that, please point me in the direction
I have been there. If i type text in that does not mean it is in the list
Like myComboPopup.AddRow(“Here is a choice”)
You need to use the Change event handler, test wether the entry is already in the list, and if not add it.
NOTE: 'If the combobox’s Autcomplete property is True, typing in the editfield will select a matching menu item if one exists, however this does not fire the combo’s Change event.
'Selecting an item from the menu fires both the Change event and the TextChanged event.
Something like this (from an older project of mine):
The custom class ComboboxWithAttachedList has a property AttachedList() As String
and the following code in the Change event
[code]Sub Change()
// check if the entry is already in the list, and if not add it to the list and the combobox menu
If IsInList( AttachedList, me.Text ) = False then
// add the new entry to the list
AttachedList.Append me.Text
// sort the list alphabetically
AttachedList.Sort
// update the combobox menu -> this deletes also the current text, so keep it in atemporary variable
dim currentText as string
currentText = me.text
me.DeleteAllRows
PopulateComboBox( me, AttachedList )
me.text = currentText
end if
End Sub[/code]
In a module called ComboBoxExtensions I have
[code]Function IsInList(List() as String, item as String) As Boolean
// check if the entry is already in the list, and if not add it to the list and the combobox menu
dim i, last as integer
last = UBound( List )
for i = 0 to last
if item = List(i) then
return True
end if
next
return False
End Function[/code]
and
[code]Sub PopulateComboBox(target as ComboBox, List() as string)
Dim i, last as Integer
target.DeleteAllRows
last= UBound( List )
For i=0 to last
target.addRow List(i)
Next
End Sub[/code]
[quote]You need to use the Change event handler, test wether the entry is already in the list, and if not add it.[/quote]. Thanks Markus. Sigh.
I was hoping it was a method or event I was missing. It looks complete.
I just tried my solution in the latest Xojo, still works fine.
You don’t need to have a custom class, you can check the entries on the fly, but I found my attachedList useful for my purposes
Thanks again. I can use elsewhere the IsItInList and probably should have written one.