How to set the Listbox ActiveCell to “Autocomplete” ?

This was running in my brain’s background from sometimes and I tried to implement that minutes ago.

So, I first get my code from a demo project (fro this forum: I do not had it handly).

I checked it from the project and saw that I have to subclass the TextField (in my case).

So, I read the Listbox entry in the documentation and now I get the Reference of the ActiveCell TextField (takes time to do).

And now comes the disaster: How can I SubClass the ActiveCell TextField ?

Nota: I develop this project on El Capitan, but it will be deployed on Windows (probably Windows Seven).

Used code to get a reference to the TextField (from a Listbox1.CellClick Event):

[code]Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
Dim LB_TE As TextEdit

Me.CellType(row,column) = ListBox.TypeEditableTextField

LB_TE = Me.ActiveCell
End Function[/code]

In the debugger, I can watch LB_TE is a real TextEdit object.

Ideas ?

There is a blog post about adding autocomplete to a TextField.

What if you subclass a TextField and assign the interface, as described in the blog post, to your subclassed TextField class.
In your CellClick event, you refer to the subclass instead of referring to the TextField itself.

Not sure if it works. But theoretically, it should. Right? At least, it is worth giving it a try…

Thank you Edwin.

I think my code comes from there. It works fine.

The TextField I want to subclass is a Listbox.ActiveCell…

But here, I want to implement it into a Listbox, so the user can add Names and have autocomplete to help typing / avoid mistyping issue(s).

Well… That was kinda what I was talking about. I haven’t tested it, but I think you might be able to cast the ActiveCell into the subclass. If that does work, you might be able to get it working inside a ListBox.

I am not in Xojo now. I have some deadlines, and just have the forum open on my second screen, so can’t test the subclass idea myself. But just trying to pass along some ideas :slight_smile:

I was not sure of your answer too ;).

LB_TE (from my code above) is a reference to the Active Cell (the TextField). I checked (useless) to set the text as Bold while editing and… it works (only when editing):

LB_TE.Bold = True

Unfortunately (I think), LB_TE.Super = something cannot works: the Super keyword is colored in blue (I do not even try to run).

I’m going to red Cast from the docs.

What I meant is something like this:
You add a class and set it’s super to TextField. You add all the interface and methods found in the Blog Post.

Next in your CellClick event:

[code]Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
Dim LB_TE As MyTextFieldSubClass

Me.CellType(row,column) = ListBox.TypeEditableTextField

LB_TE = Me.ActiveCell
End Function[/code]

It does not change your code too much. It just uses the autocomplete functionality you added in your subclass, instead of the base class (TextField).

Doh !

I was on something else, but I loose the Super at LB_TE = Me.ActiveCell time.

No, this does not works on the last line:

LB_TE = Me.ActiveCell

The error is… Type Mismatch Error. Expected Class AutoComplete, but got Class TextEdit.

AutoComplete is the name of my TextField SubClass.

Time to lunch. Have a good lunch ! I will get back in a couple of hours.

That is not possible.

You cannot.

You would have to copy all code from that blog post into a Listbox subclass and do it there (by using AddHandler for the events of ActiveCell).

Still hungry, but while driving home, I had an idea:

LB_TE = AutoComplete(Me.ActiveCell)

But I got an IllegalCastException…

Nota: LB_TE is Dimed as TextEdit (else: error occured), the .CellType is declared as TextField and, at last, LB_TE iSa TextField. It tooks me a while to understand that.

AutoComplete Super is TextField.

Last checking (before I start to eat):

[code] LB_TE = Me.ActiveCell

LB_TF = AutoComplete(LB_TE)[/code]

I also get an IllegalCastException…
LB_TF is Dimed as TextField.

Not possible, see my previous post.

Hi Eli: I do not saw your previous post (it certainly comes when I hit Post a Reply…

A good idea impossible to implement: a real shame ! :wink:

Read: 50182 in Feedback.