How to change Combobox value according to case

Asked

Viewed 26 times

-1

The combobox has two options the Letter option and numbers option.

When I set one, I need it to appear in another comboBox only the information corresponding to the selected option.

The comboBox is not connected to a db, and yes has content in component items property.

Selecting Letras appear only Letters,

Selecting Números appear only the numbers.

Thank you

1 answer

0


You can do it in several ways, but I suggest that as you are starting out, try doing it the following way to exercise logic.

  1. Create a combobox with the name cmbType and add the "Letters" items and "Numbers".
  2. Create a combobox with the name command.
  3. Add a event handler Selectindexchanged cmbType by clicking two times on it or in the Events tab of the properties window.
  4. Alter the code as shown below:
private void cmbTipo_SelectedIndexChanged(object sender, EventArgs e)
{
    if (cmbTipo.Text.Equals("Letras"))
    {
        cmbOpcoes.DataSource = new string[] { "A", "B", "C" };
    }
    else
    {
        cmbOpcoes.DataSource = new int[] { 1, 2, 3 };
    }
}

Browser other questions tagged

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