ListBox strange behaviour

Strange behavior

I am unsure of what happens, but in a window, I allow the user to change the ListBox Heading (in a second window).

I consistently (more or less) get 0, 1, 2, … as heading: sometimes in the <set-new-heading—window> or back from that window.

After wasting my time on that, I get a correct working behavior. Yesterday I noticed that it does not worked one time. Earlier today, I decided toc heck what happened and I had a change in mind:

The line:

TargetWindow.LB.Heading(-1) = Self.LB.Heading(-1)

Was changed to:

[code]Dim TheHead As String

TheHead = Self.LB.Heading(-1)
TargetWindow.LB.Heading(-1) = TheHead

And while I was at it, I realized that I’d better move the column count line before filling the Heading (in case Xojo does not set the ListBox ColumnCount according to the Heading passed string).

Run, load a text file, yes ! That file have een loaded correctly…
Yes! The headings are copyed correctly to the window that allows the Heading change and back to the original window.

Now, how can this be ? If someone asked be some days ago if the following line work I would answer YES !

// Copy the ListBox Heading from Window 1 to Window 2: window2.LB.Heading(-1) = Window1.LB.Heading(-1)

Ideas ?
Experiences ?

When/Where are you copying the headings over?
If you’re doing it in the Close event the Listbox is probably destroyed by the time you’re trying to copy it.

Notice in the IDE when you enable headings but have no heading value the default values are 0, 1, 2, etc… so we know that those are the default values Xojo uses when you don’t supply any data to the headings.

My guess is the documentation on Listbox.Heading only says you can set the headings with Listbox.Heading(-1), it never says you can read from it. That may be why you’re getting the default values, Listbox.Heading(-1) may be returning nothing.

EDIT: Additional scanning of the documentation says “empty strings will use the default header” so you’re definitely not sending any data.


Thank you for your anwser.

The user click in a ToolBar button to be allowed to modify the ListBox Header.

I added there (in ToolBar Action) the Header change. I am able to see the headers in both windows.

At last, two simple changes makes the whole working:

move the target Window’s ListBox Column Count one line up (before setting the Header strings) *
copy the header string to set (original Window), THEN set the header string (the target Window).

  • I know I was wrong because I saw one column (or two) with strings (in the Target window) and the columns remainder are auto-filled with numbers (2, 3, 4, …).

That is only because they do not had in mind an example where it is pertinent to do that.
NOTE: in the syntax box, there are the two syntax (read / write the Headers).

I am not able to modify my text, so I do it here:

where it is pertinent to do that
where it is pertinent to copy the Header strings and do something with them.