How to use Winforms Textbox Autocomplete for multiple phrases?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to use Winforms Textbox Autocomplete for multiple phrases?

Post by ic2 »

In our VO based e-mail program the user can enter an e-mail address which is autocompleted (=after adding any character, the next e-mail addresses still matching the typed part is displayed, the autocompleted part is selected so the user can keep entering extra characters until either the suggestion is correct or a new address has been entered). This could be cleverly handled using the VO events like EditChange.

This can obviously not be copied (easily) to a Winforms Textbox we use in the X# version of the program as events are or react different and nor did I think I needed to do that, as there in Autocomplete property readily available there.

But no. As often with .Net some build in feature looks promising but it is only doing a part of what you want and the functionality is never extended during the years after it was introduced. What is missing here is an option to enter and autocomplete multiple e-mail addresses, (, or ; separated). In our VO program these extra addresses also autocomplete. In the Winforms Textbox they don't.

I found some complicated tricks to go around that (something with implementing a listbox on a textbox) and reading the comments this doesn't completely solve my issue either.

My question is if anyone solved Autocomplete either to work with multiple phrases or by a not "out-of-the-limited-.Net-Box" solution like we did in VO?

Dick
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

How to use WInforms Textbox Autocomplete for multiple phrases?

Post by Jamal »

You can double click the textbox control to generate the TextChanged method, such as:

Code: Select all

PRIVATE METHOD textBox1_TextChanged(sender AS System.Object, e AS System.EventArgs) AS VOID STRICT
            // your code
           RETURN
        END METHOD
EditChange in VO is a Window event while the TextChanged Event in .NET Winforms is at the control level.

If you want to have an TextChanged for all controls to mimic EditChange, then you can create a method to attach an EventHandler using ForEach for all controls on the form. The link is C# which be easily converted to X#:
https://stackoverflow.com/questions/190 ... es-in-form

Jamal
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to use WInforms Textbox Autocomplete for multiple phrases?

Post by ic2 »

Hello Jamal,

Thanks for your reply. I did try TextChanged but didn't get the AutoComplete working as it works in VO, I think mainly because these events just react differently than those in VO.

I will first explore another option, which is removing the current entry once a user types a : or , and then the built in Autocomplete keeps working. On leaving the control all entries are filled in again. I will have to add a control showing the "moved" entries, I think with an option to remove entries there. Let's see if I get that working adequately in less time.

Dick
Terry
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

How to use Winforms Textbox Autocomplete for multiple phrases?

Post by Terry »

Dick

If I understand things correctly (Basically I am guessing) and were using C#, then following on from what Jamal says I would intercept the KeyDown Event and Generate a sub-class (Selection) ListBox with suitable update logic. Any pre-written AutoComplete logic is likely to be too restrictive anyway.

Terry
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to use Winforms Textbox Autocomplete for multiple phrases?

Post by ic2 »

Hello Terry,
Terry post=25296 userid=4511 wrote:Any pre-written AutoComplete logic is likely to be too restrictive anyway.
Indeed and that is what often disappoints me. There are still very few things which I handle more efficiently with built in .Net functionality than I've done for over 25 years with VO and great libraries (like FabTools, bBrowser, SEUIXP and more).

Getting this done for VO wasn't easy either but unless my alternative idea works we will basically have to start over as all Winforms events works a bit differently. I tried those first and hence I know it is going to take a lot of time...

Dick
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

How to use WInforms Textbox Autocomplete for multiple phrases?

Post by Jamal »

Another option is by using KeyUp method, then handle the e.KeyCode, and based on that call the various methods of the textBox control via Select(), Focus() and ScrollToCaret(), etc and update your textBox.Text value.

As you have discovered by now, I suggest you forget the VO way of event handling and focus on the .NET way and will be easier. This requires patience and more practice. Of course, it is all up to you.
Post Reply