AutoComplete with TextBox and formatting

Is there an easy way to format the text in a standard TextBox control that uses an AutoComplete component based on the data source of the AutoComplete?

For example, if the AutoComplete is bound to a DataTable with the "RecordID", "Description" and "Code" columns and the TextBox is bound to the "RecordID" column of the same table, how would I make the actual text in the text box look like this:
"1234 - SomeDescription, SomeCode"

...but still be only bound to the RecordID value?

Is this something that the AutoComplete can help with when an item is selected?

2 Replies

AR Anupama Roy Syncfusion Team November 27, 2006 07:42 AM UTC

Hi Mark,

Sorry for the delay in response.

Yes,It is possible to format the text in a standard TextBox control that uses an AutoComplete component based on the data source of the AutoComplete.You can handle the AutoCompleteItemSelected event and retrieve other columns of same table using args.ItemArray[Index] where you need to specify the index of column required.Also,the args.SelectedValue will display the required text as shown below.

Code:

private void autoComplete2_AutoCompleteItemSelected(object sender, Syncfusion.Windows.Forms.Tools.AutoCompleteItemEventArgs args)
{
string CurrentText= this.textBox2.Text;
args.SelectedValue = CurrentText + args.ItemArray[args.MatchColumnIndex].ToString() +"-"+ args.ItemArray[0].ToString()+ ","+args.ItemArray[1].ToString ();
args.Handled = true;

}

Sample


Kindly let me know if this does not meet your requirements.

Thanks for choosing Syncfusion products.


Regards,

Anu.


MA Mark Atkinson November 27, 2006 03:40 PM UTC

Works like a beauty. Thanks!

Loader.
Up arrow icon