Combobox autocomplete .net

0

I saw this code and I want to implement it, in a datagridview, but the problem is that it only allows writing a character, but it works. in autocomplete, how could this allow you to completely write the word.

  private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            string name = string.Format("{0}{1}", comboBox1.Text, e.KeyChar.ToString());
            DataRow[] rows = dataTable.Select(string.Format("place LIKE '%{0}%'", name));
            DataTable filteredTable = dataTable.Clone();
           foreach(DataRow r in rows)
               filteredTable.ImportRow(r);
           comboBox1.DataSource = null;
           comboBox1.DataSource = filteredTable.DefaultView;
           comboBox1.DisplayMember = "place";

        }
    
asked by JuanL 15.02.2018 в 03:15
source

1 answer

0

If it's winforms, with a textbox with keypress that function should work well.

    private void texbox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        string name = texbox1.Text;
        if (string.IsNullOrWhiteSpace(name)){ 
           datagridview1.DataSource = null;
           datagridview1.databind();
        }
        DataRow[] rows = dataTable.Select(string.Format("place LIKE '%{0}%'", name));

       datagridview1.DataSource = rows;
       datagridview1.DataBind();

    }

if it is Web you must make an asynchronous function with javascript that recovers the information.

    
answered by 19.02.2018 в 18:43