Hi friends
I want to refresh my combo box .
i have even used the combobox.refresh() syntax but it does nothing!
need help

Dani AI

Generated

In WinForms, repainting is not the same as reloading. Refresh() only redraws the control; it does not repopulate the list or change selection state. If your ComboBox is data-bound, the most reliable way to "refresh" it is to reset the binding and reassign the data source. This also avoids event storms while items are being replaced.

Example (WinForms, VB.NET):

' Pause UI updates while changing the list
ComboBox1.BeginUpdate()

' If using a BindingSource, refresh the underlying data then reset bindings
Dim bs = TryCast(ComboBox1.DataSource, BindingSource)
If bs IsNot Nothing Then
    bs.DataSource = LoadItems()      ' your reload routine
    bs.ResetBindings(False)
Else
    ' Not using a BindingSource: rebind directly
    ComboBox1.DataSource = Nothing
    ComboBox1.DisplayMember = "Name"
    ComboBox1.ValueMember = "Id"
    ComboBox1.DataSource = LoadItems()
End If

' Optional: clear the current pick without changing the list contents
ComboBox1.SelectedItem = Nothing

ComboBox1.EndUpdate()

For ASP.NET WebForms (DropDownList), rebinding happens on the server. Ensure you only bind when appropriate and call DataBind() after setting the data source:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        BindGuests()
    End If
End Sub

Private Sub BindGuests()
    Dim items = LoadGuests()
    ddlGuests.DataSource = items
    ddlGuests.DataTextField = "Name"
    ddlGuests.DataValueField = "Id"
    ddlGuests.DataBind()
End Sub

Tips: detach event handlers while reloading if your logic runs on SelectedIndexChanged/SelectionChangeCommitted, and prefer a BindingSource so you can update the list and call ResetBindings instead of manually manipulating item collections.

Recommended Answers

All 10 Replies

combobox.items.clear()

combobox.SelectedIndex = -1

Hi,

If your combobox is set with the "DropDownList", then
use Combobox1.SelectedIndex = -1

I've experimenting, but it did not work

Please start a new thread and post the code that doesn't work so that we can offer suggestions.

ComboBox.Items.Clear()

try this
ComboBoxguest.Items.Clear()
then load your combobox again
ext
ComboBoxguest.Items.Clear() 'clear combobox
guest()'i load again combobox from this methode

Try: .refresh(), then .items.clear(), then invalidate()

Hi,

If your combobox is set with the "DropDownList", then
use Combobox1.SelectedIndex = -1

try combobox1.text = ""
it works for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.