Fill in Combobox

Asked

Viewed 516 times

2

In a User Registration Form, I have a combo box UF (which loads the data from an sql table), when writing in Combox the system needs to go searching the data and presenting despite those that coincide with the typed. I’m doing it this way:

    private void carregaComboEstadoCivil()
    {
        ProfissionalBLL profissional = new ProfissionalBLL();
        profissional.carregaComboEstadoCivil(cbxEstadoCivil);

        cbxEstadoCivil.KeyPress += new KeyPressEventHandler(cbxEstadoCivil_KeyPress);
    }

Classe Profissional BLL

    public void carregaComboEstadoCivil(ComboBox combo)
    {
        FuncionsDAL carrega = new FuncionsDAL();
        DataTable tabela = carrega.listaEstadoCivil();

        DataRow linha = tabela.NewRow();

        combo.DropDownStyle = ComboBoxStyle.DropDown;
        combo.AutoCompleteMode = AutoCompleteMode.Suggest;
        combo.DataSource = tabela;
        combo.DisplayMember = "Descricao";
        combo.ValueMember = "ID";
        combo.Update();
        linha["ID"] = 0;
        linha["Descricao"] = "Selecione...";
        tabela.Rows.InsertAt(linha, 0);
    }

Event of the Keypress

    private void cbxEstadoCivil_KeyPress(object sender, KeyPressEventArgs e)
    {
        cbxEstadoCivil.DroppedDown = true;

    }

But it’s not working.

The combobox opens allows me to write but not only shows the record that matches what I wrote it shows me all the record.

  • Post the Keypress event implementation, the way it is just loads the data.

  • private void cbxEstadoCivil_KeyPress(Object Sender, Keypresseventargs e) { cbxEstadoCivil.Droppeddown = true; }

  • What’s not working? The data is not shown on the screen or the search does not work?

  • Search screen does not work!

1 answer

1


    //criando palavras sugeridas
    var source = new AutoCompleteStringCollection();
    source.AddRange(new string[]
            {
                "Masculino",
                "Feminino",
                "Outro"
            });
    // criando combo
    var combobox = new ComboBox
    {
        AutoCompleteCustomSource = source,
        AutoCompleteMode =
            AutoCompleteMode.SuggestAppend,
        AutoCompleteSource =
            AutoCompleteSource.CustomSource,
        Location = new Point(20, 20),
        Width = ClientRectangle.Width - 40,
        Visible = true,
        DropDownStyle = ComboBoxStyle.DropDown
    };
    combobox.Items.Add("Masculino");
    combobox.Items.Add("Feminino");
    combobox.Items.Add("Outro");

Browser other questions tagged

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