Popular a Combobox from the selection of another Combobox

Asked

Viewed 111 times

1

I really have no idea how to do this, but if this is really possible it would be very helpful to me, I tried in some ways but none of it worked

I have a ComboBox cboBusca where I select what I want to search for in DataGridView

Ex: LINES, FIDELITY, CONTRACT and etc

And another ComboBox cboCriterio where I would define what I want to seek

Ex: A+, NEW CONTRACT, EXPIRED, etc

So I would basically like after I choose a value on cboBusca he populated the cboCriterio since what I’m filtering is kind of fixed values I could manually add what I want to appear on cboCriterio after selecting a particular option on cboBusca.

  • The items of cboCriterio will be filled by Database records, correct?

  • not myself would fill it manually as I had quoted, for example IF(cboBusca == FIDELIDADE){
cboCriterio.Items.Add("Fidelizado");
cboCriterio.Items.Add("Não Fidelizado");
cboCriterio.Items.Add("Vencido");

  • but that way it doesn’t work but the logic would be this

1 answer

3


Create the event SelectedIndexChanged to the cboBusca and test in this way:

private void cboBusca_SelectedIndexChanged(object sender, EventArgs e)
{
    cboCriterio.Items.Clear();

    if (cboBusca.SelectedIndex == 0)
    {
        cboCriterio.Items.Add("Fidelizado"); 
        cboCriterio.Items.Add("Não Fidelizado"); 
        cboCriterio.Items.Add("Vencido");
    }
    else if(cboBusca.SelectedIndex == 1)
    {
        cboCriterio.Items.Add("Expirado"); 
        cboCriterio.Items.Add("Não Expirado"); 
        cboCriterio.Items.Add("Teste");
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.