AutoComplete TextBox From a Data Source

Friends,

Anyone attempted to build an AutoComplete textbox filled with data from a datsource Since the autocompletecustomsource property only seems to support string arrays, I should be able to loop through a column in a table, create an array from the data and assign that array to the autocomplete source. Anyone tried this and could you post the code if available

J.H.



Answer this question

AutoComplete TextBox From a Data Source

  • Ian Cummings

    Yes but this solution doesn't retain the bindings, anyone knows of a better way to do it

    The solution I tried didn't work.

    Me.ProdottiBindingSource.DataSource = Archivi.MainForm.DataSetArchivio

    Me.BindingSourceGruppi.DataMember = "Prodotti"

    Me.TextBoxCodice.DataBindings.Add(New System.Windows.Forms.Binding("AutoCompleteCustomSource", Me.ProdottiBindingSource, "Codice", True)


  • root2

    I found the solution.....

    The AutoCompleteCustomSource is actually a string collection as opposed to an array. You can itterate through a datatable and add items to the collection as follows:

    foreach (DataRow dr in myDataSet.myTable.Rows)
    {
    this.toolStripTextBox1.AutoCompleteCustomSource.Add(dr["myColumn"].ToString());
    }

    Make sure you have your AutoCompleteSource set to CustomSource, works just grand.

    J.H.


  • AutoComplete TextBox From a Data Source