How to load ComboBox in C #? [closed]

1

I have 2 ComboBox: the 1st represents the provinces, the 2nd the municipalities. When the user clicks on ComboBox 1 and select a province I want their counties to appear in ComboBox 2.

    
asked by anonymous 10.08.2016 / 16:23

1 answer

1

Using database, create a DropDown event in the combo that does the following:

//LIMPA OS ITENS DO COMBO
nomedoCombo.Items.Clear();

//CONECTA NO BANCO E RETORNA A CONEXÃO (DEVE TER SUA MANEIRA DE CONECTAR, ESSA É A MINHA)
ClassBancoDeDados Conn = new ClassBancoDeDados();


//PREPARA O SQL
String sSql = " SELECT campo FROM tabela order by campo";

MySqlDataReader DataReader = Conn.SqlQuery(sSql);
try
{
    if (DataReader.HasRows)
    {
       //se existem dados, serão adicionados no combobox
        while (DataReader.Read())
        {
            nomeDoCombo.Items.Add(DataReader.GetString(0));
        }
     }
}
catch
{
     return;
}

I like to put in the dropdown pq will always bring updated

Until next time

    
10.08.2016 / 17:50