0
votes

I have a typical combobox with drop down items. An item in the dropdown consists of a string with a code then a space, then the description of the code. I'm trying to get the text of the combo box to show just the code after the selection has been made, but there is a race condition in which my the text field is not being updated by the combobox until AFTER I change it. How do I force the combobox to update itself, so I can change the text afterwards.

With code_combo_box
     AddHandler .SelectedIndexChanged, AddressOf update_desc
End With

Private Sub update_desc()

  If code_combo_box.SelectedIndex >= 0 Then
     Dim temp_string As String() = code_combo_box.SelectedItem.split(" ")
     code_combo_box.Text = temp_string(0)
  End If

End Sub

The combobox gets updated to the selected item after update_desc is called wiping out my change.

1
Which UI technology is this? Windows Forms? WPF? Something else? It's probably reasonably straightforward to fix your item list and/or list display logic to get the behavior you want, but the method will depend on the UI technology you're using.Craig
It is Windows Forms.John
I would suggest that you search the web for how to create a multicolumn combobox. That way, your drop-down will display two columns of data (code and description) but the control itself will only display one and you won;t have to mess around with trying to change the text after the fact.jmcilhinney

1 Answers

0
votes

I figured out the answer which is to flag the event as handled when I enter the update_desc subroutine. So I needed to catch the events when entering the routine with

update_desc(sender as object, e as system.eventargs)

and then inside the routine simply use

e.handled = true

and the event would not continue to fire after leaving the routine and my changes would remain.