Home › Forums › WinForms controls › Other WinForms controls › Clear combobox text
-
AuthorPosts
-
#18202 |
Hi
How can I clear the text that is displayed in the combobox? I clear all the items by using combobox.items.clear() but this does not clear the text that may have been selected in a previous selection.
Thanks
Nick Steele
Imported from legacy forums. Posted by Nick (had 4561 views)
This should have worked fine, can you send me the code you use to fill the comboBox in question?
Imported from legacy forums. Posted by Matt (had 221 views)
Hi
Heres whats happening. I have two combo boxes one named job and one named unit. The job combo is populated with jobnumbers. When a job number is selected it populates the unit combo with relevant unit numbers. The user then selects a unit and the program continues. When a user now selects a different job the unit combo is cleared and repopulated with new unit numbers. The problem I have is that the unit that was selected in the first go around is still showing and I need the unit combo display to be blank at this stage. Heres the code:
Private Sub cboJobNum_SelectedItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboJobNum.SelectedItemChanged
Dim strSql As String
Dim cmd As MySqlCommand
Dim drData As MySqlDataReader
Dim strUnitNum As String
Dim ComboItem As Xceed.SmartUI.Controls.ToolBar.ComboBoxItem‘clear any old items
cboUnitNum.Items.Clear()‘first populate the stock type combo
strSql = “SELECT UnitNum FROM Shared.tblProject WHERE ProjectNum ='” & cboJobNum.SelectedItem.Text & _
“‘ ORDER BY UnitNum”
‘start a reader
cmd = New MySqlCommand(strSql, cnn)
drData = cmd.ExecuteReader
‘Add the list of crates to the Crate Combo Box
Do While drData.Read()
strUnitNum = drData(“UnitNum”)
ComboItem = New Xceed.SmartUI.Controls.ToolBar.ComboBoxItem(strUnitNum)
cboUnitNum.Items.Add(ComboItem)
Loop‘close the reader
If Not drData Is Nothing Then
drData.Close()
End If
End Subthanks Nick Steele
Imported from legacy forums. Posted by Nick (had 560 views)
You need to clear the text box of the ComboBox by setting the SelectedItem to null.
i.e.:
cboUnitNum.Items.Clear()
cboUnitNum.SelectedItem = NothingImported from legacy forums. Posted by André (had 4482 views)
-
AuthorPosts
- You must be logged in to reply to this topic.