winforms - C# AutoComplete -
I am trying to add an autocomplete feature in a text box, the results are coming from the database. They come in the form of
[001] last, first middle
, currently you have to type [001] ... show entries for . The problem is that I want to complete it, even if I write first name first if one entry
[001] Smith, John D
If I start typing John, then this entry should be shown in Auto's results.
Currently the code looks like this
Autocomplete string collection ACCC = new auto-compost string compilation (); TxtBox1.AutoCompleteCustomSource = ACSC; TxtBox1.AutoCompleteMode = Auto Complete suggestion; TxtBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; .... (for int (i.l. = Results. Rao [i]; Acsc.Add (line ["description"] toString ().); }} The result is a dataset with query results
query is a simple search query by using the same statement if we Do not use autocomplete and toss the results only in an array, the correct results are returned.
Any advice?
Edit:
Em> {0} is the placeholder for the search string.
Existing autocomplete functionality only supports search by prefix
Some people have their own completed actions implemented by overriding the OnTextChanged event. Perhaps this is your best bet. For example, you can add ListBox to the TextBox and set its default visibility to false. Then you select the OnTextChanged event TextBox and the SelectedInchangeChanged event to use ListBox and select the item Can do for you.
It works very well as a rudimentary example:
public form 1 () {InitializeComponent (); ACCC = New Auto Complex String Coalition (); Textbox1.AutoCompleteCustomSource = ACSC; Textbox1.AutoCompleteMode = Autocomplete Mode.None; Textbox1.AutoCompleteSource = AutoCompleteSource.CustomSource; } Private Zero button 1_Click (object sender, EventArgs e) {acsc.Add ("[001] some type of item"); Acsc.Add ("[002] Some Other Items"); Acsc.Add ("[003] an orange"); Acsc.Add ("[004] I like pickle"); } Zero text box 1 tag (Object Sender, System.EventArgs e) {listBox1.Items.Clear (); If (textbox1.Text.Length == 0) {hide (results); Return; } Foreach (String S. eto complextextours in text box 1) {if (S. Maintenance (text box 1. text)) {console. Videoline ("Text found in:" + s); ListBox1.Items.Add (s); ListBox1. Person = true; }}} Zero ListBox 1 Sealed Intex (Object Sender, System.EventErgus E) {textbox1.Text = listBox1.Items [listBox1.SelectedIndex] .ToString (); HideResults (); } Zero ListBox 1_LostFocus (Object Sender, System.EventArgs e) {hideResults (); } Hide zero (result) {listBox1.Visible = false; } Without a lot of effort, you can: Attach text to the text box, capture additional keyboard commands, and much more.
Comments
Post a Comment