John
John

Reputation: 1338

Forcing a combo box to update its text field

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.

Upvotes: 0

Views: 356

Answers (1)

John
John

Reputation: 1338

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.

Upvotes: 0

Related Questions