Refresh a Combo Box in VB.Net

0

I have a problem (maybe very simple) but I have not been able to solve it, it turns out that I'm doing a form for Visual Basic .Net records, within the same I have combobox that when I load the form for the first time everything is perfectly but when making a record I have to clean the fields (textBox) and update the comboBox of the form but I do not do the task as I would like (I left the combobox blank). The cleanup method I do the following

Public Sub limpiarCampos()
        txtRFC.Text = ""
        txtCodigoCiudadano.Text = ""
        cboTipoAccionista.SelectedIndex = -1
end sub

I very much appreciate the suggestion that you can give me, thank you very much in advance.

    
asked by Silvestre Silva 29.11.2017 в 21:28
source

2 answers

1

Good Wild,

The problem is that by doing what you show us, you are not cleaning the DataSource of ComboBox , you are simply indicating that you have not selected any Item .

To empty the ComboBox of data you can do it in the following way:

If the ComboBox has filled it with a DataBound (DataSource) you should put the following:

cboTipoAccionista.DataSource = null;

On the other hand, if you have not filled it with a DataBound (DataSource) you must put the following instruction:

cboTipoAccionista.Items.Clear()
    
answered by 30.11.2017 в 08:18
0

If what you need is for the combo to show a value, instead of -1 put the index of the value you need ( cboTipoAccionista.SelectedIndex = 0 ).

If you want to refresh the values it contains, load your combo in a method
(same that you will execute in the Load) and sends to call the method after cleaning.

    
answered by 29.11.2017 в 21:47