Override or reload autocomplete rule

I have a text box that sends some commands to the tool. I added an autocomplete function to this text box, and now everything will be easier.

What I'm going to improve is to add that when the user enters a command (just text), while autocomplete finds a match, it also shows a description for this command.

At the moment, I have all the AutoComplete lines in a text file, and I load it when the application starts. The text file contains the following lines:

*IDN? #Query the instrument for identification *RST #Resets the instrument 

So what happens in my application is that since AutoComplete is in SuggestAppend mode, the command description also gets into the text box (it will be the same if I only put it in Suggest mode)

I need to know how to get AutoComplete to add text, and its

  • Does not add text starting with # char when adding suggested text
  • Trim () the text to avoid the space that you see in the source of the text file.

UPDATE 1 Well, I think the only way is to create a new class and inherit from AutoCompleteStringCollection . And in this new class, somehow override the return method to return (add) the proposed text. I really don't know what to do:

 class MyAutoCompleteCollection : AutoCompleteStringCollection { //How to override Get function of AutoCompleteStringCollection class? //It is not avilable to override :( } 

UPDATE 2 I found out that methods in AutoCompleteStringCollection are not valid. I'm looking for a way to change the way [] (to be honest, I donโ€™t know what to call it!) Works. Does anyone know about this?

enter image description here

UPDATE 3 When text without #DESC falls into the text box, I have an event handler for KeyDown that will pass the command to the tool.

+7
source share
5 answers

Instead of trying to combat the autocomplete functionality implemented by Microsoft, I highly recommend using a multi-column combo box instead.

All of the ones we used support autocomplete, so you can save your command in the first column and have this value, and then save your description in the second column.

There are a huge number of controls available for purchase (Infragistics, Intersoft, Syncfusion, etc.), and you can probably find free or self-created versions on various sites, such as CodeProject.

Going along this route should save you a lot of time.

+1
source

Stay using the SuggestAppend method and load the text file as a custom source for the TextBox auto-complete feature.

You can use the Leave event for a TextBox to remove all text after # and trim the result:

 private void textBox1_Leave(object sender, EventArgs e) { textBox1.Text = textBox1.Text.Remove(textBox1.Text.LastIndexOf("#")).Trim(); } 

Thus, the description remains in the autocomplete list, but as soon as you select or leave a text field, only the command remains.

+1
source

Here is a link that has a complete example for Autocomplete

 http://technet.microsoft.com/en-us/query/chff42zw 
0
source

As an answer to your update nr. 2: [] is an index property.

Your class implements a collection. You can get the item at index X using the collowing code:

 var thirdItem = myAutoCompleteCollectionInstance[3]; 

Index properties can be created manually using the code below, which you can use to customize the order by returning the necessary elements at the specified indices.

  public string this[int index] {get ...} {set...} 
0
source

The AutoComplete property of the text field is set in the SuggestAppend language, which means that it adds both text and description. Therefore, you need to set the AutoComplete property in the text box only to the value "Suggest".

According to MSDN, the Autocomplete property can take four enumeration values, namely

The following are AutoCompleteMode values:

 Append : Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters. Suggest : Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings. SuggestAppend : Appends both Suggest and Append options. None : Disables automatic completion. This is the default. 

Try these values โ€‹โ€‹instead of subclassing AutoCompleteStringCollection.

-one
source

All Articles