We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Autocomplete - Assigning New Datasource At Runtime

Is it possible to set the datasource of an Autocomplete to a completely different dataset at runtime?

The datasets have different numbers of columns.

I tried making two different autocompletes on the form.

But, is it possible to "attach" the or set the disabled/enabled for an autocomplete in code for a particular control or must it only be done at designtime in the GUI?

Thanks.

1 Reply

LS Lingaraj S Syncfusion Team July 5, 2010 02:37 PM UTC

Hi JD West,

Thank you for your interest in Syncfusion products.

Yes. You can achieve by using SetAutoComplete method in AutoComplete as shown below

private void Form1_Load(object sender, EventArgs e)
{
DataTable dt1 = new DataTable();
dt1.Columns.Add("Col1");
dt1.Columns.Add("Col2");
for (int i = 0; i < 10; i++)
{
dt1.Rows.Add(new object[] { i, 1 });
}
DataTable dt2 = new DataTable();
dt2.Columns.Add("Col1");
dt2.Columns.Add("Col2");
dt2.Columns.Add("Col3");
for (int i = 0; i < 10; i++)
{
dt2.Rows.Add(new object[] { i, 1 ,2});
}
this.autoComplete1.DataSource = dt1;
this.autoComplete2.DataSource = dt2;
this.autoComplete1.SetAutoComplete(this.textBox1, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.AutoSuggest);
this.autoComplete2.SetAutoComplete(this.textBox1, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.Disabled);
}
private void button1_Click(object sender, EventArgs e)
{
this.autoComplete1.SetAutoComplete(this.textBox1, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.Disabled);
this.autoComplete2.SetAutoComplete(this.textBox1, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.AutoSuggest);
}
private void button2_Click(object sender, EventArgs e)
{
this.autoComplete1.SetAutoComplete(this.textBox1, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.AutoSuggest);
this.autoComplete2.SetAutoComplete(this.textBox1, Syncfusion.Windows.Forms.Tools.AutoCompleteModes.Disabled);
}


Also please refer the documentation from following link.
http://help.syncfusion.com/ug_82/WindowsFormsUI_Tools/EnablingAutoCompleteInTextBoxArea.html

Please let me know if you have any queries.

Regards,
Lingaraj S.

Loader.
Live Chat Icon For mobile
Up arrow icon