PowerToolbar: Managing DropCombo control items

I got an email this morning from a customer who was trying, without any success, to change the text of items in a Drop Combo control in PowerToolbar at runtime. The simplest way would be to simply use:

Toolbar1.SetItemText(MyItem,'My Text')

Unfortunately that only works for drop buttons, not Drop Combos. I figured it would be a simple task to add a method to do this but ran into a brick wall. The brick wall was the APIs used to construct Drop down Combo controls do not have any messages or methods to change the text for a given item! It seems to be set in stone once the item is created. So what can you do? The simple answer is to recreate the Drop Combo items! It is very fast and as far as I can tell it does not cause any flicker.

If you want to restore the text in the entry field, you need a single CSTRING variable to contain the text. Below is the code needed to reset the items in the Drop Combo:

Loc:Str = Toolbar1.GetText(ID1_DropCombo)
Toolbar1.DeleteItems(ID1_DropCombo)
Toolbar1.AddComboItem(ID1_DropCombo, 'NEW Drop combo item 1', )
Toolbar1.AddComboItem(ID1_DropCombo, 'NEW Drop combo item 2', )
Toolbar1.SetText(ID1_DropCombo,Loc:Str)

In this case Loc:Str is a CSTRING(100) variable that is a temporary buffer for the contents of the Drop Combo edit control. The Toolbar1.DeleteItems deletes ALL the items from the list and the next two Toolbar1.AddComboItem lines add two new items to the list. The Toolbar1.SetText resets the text in the edit control and you are back where you started except you now have updated items in your list.

Arnor Baldvinsson

Leave a Reply