ListboxCell to Textfield

I can assign a Textfield in a window to a generic textfield.
app.tf = Window1.Textfield
So I have eg selectionstart, etc. to deal with in one place.

How can I do that from a desktop.listbox, since
app.tf = Window1.Listbox1(row,column) does not work?

Cells are not individual objects, but you could store the Listbox in the global property.

App.lb = Window1.Listbox1
// App.lb.CellValueAt(row, column) = "Please don't abuse globals"

I highly advise against abusing global properties like this, it will lead to spaghetti code and projects that are hard to maintain.

1 Like

This is where you can have observers - the Textarea(s) listening for information from the Listbox, which doesn’t need to know anything about the Texarea(s).

Xojo has an example project: Design Patterns > Observer.

To explain further: for the Undo/redo handling method I hand over the textfield as a parameter.
Now I try to do the same for listbox cells, but I need to transform/assign a cell to a textfield.

@Mark:
I did not find what you mean, entering observer in the Documents I get only to Eddie’s Electronics example…

@Tim:
I don’t need the whole listbox, just a clever method to treat a cell as if it were a textfield (because there is e.g. no CellSelectionStart(row, col)). What would be a drag for maintenance is to handle each window.textfields (there are dozens) and cells (hundreds) individually.

When you are actively editing a cell, you have ActiveTextControl, which is a textfield.

…mhh, looking at the documentation, I cannot see anything like a Selectionlength feature, however I read ‘it’s read only’ at the beginning.
To enlighten me, could you provide an example where you suggest how I can manipulate any cell (eg when pressed backspace, or delete a selected portion of text, and revoke it)? In my opinion, getting it to treat like a textfield would be the simplest way.

It is a textfield. If I understand you correctly you can use the ActiveTextControl directly and pass that the same way you pass your other textfields. You may have to cast it as a TextField when you pass it in.

From the main screen, select Examples, and type Observer in the search bar. If you don’t see the main screen when starting up, create a new project and you should see it.

OK, thanks, I found it.

Now: what has that to do with my problem? Just seeing colors and no textfields in that app…
Maybe you need to explain further why that should be the solution for me.

Or are there other solutions, can’t be that I’m the first one who tries this…

It’s the principal - in that example the radio buttons know nothing about the other windows. There’s no reference to them, but they still change color when you select different radio buttons.

In your case, the listbox does not need to have a reference to the TextArea in order to send it information.

The NotifyObservers method can pass a string from the Listbox cell to TextAreas, instead of a color.

To be honest, Mark, your Observer way of doing it exceeds my understanding.

But digging further: I noticed I could use Listbox.Activecell - this is a TextField!
However, not exactly. To put the cell into such a variable, it must be a TextEdit (otherwise type mismatch error).

var f as TextField
var e as TextEdit
e = window1.listbox2.activecell

Then again, when inspecting the project, that field is indicated as type TextField…! Strange.
Name Value
e TextField

Do you see a way to convert them or even ‘link’ them together, textedit e and the textfield f variables?

You can cast it to the appropriate type.

e = TextEdit(window1.listbox2.activecell)

Window1.Listbox1(row,column) = ListBox1.TypeTextField

Puis, récupérer la référence avec ActiveCell.

Check the documentation.

The TextField Reference will be valid only during the Cell Edit, so I will say this is useless (to save a global reference)…