Filing ListBox1.Heading…

I fill a ListBox Heading using:

LB.Heading(0) = "Story #" LB.Heading(1) = "Story Title" LB.Heading(2) = "Date Start" LB.Heading(3) = "Date End" LB.Heading(4) = "Size (Bytes)" LB.Heading(5) = "Kind (Extension)" LB.Heading(6) = "Comments"

and that was good.

I had a bug there, and I squashed it. Then, I saw that code and decided to modify it to follow the “”,"","" path.

Unfortunately, this is a syntax from AddRow, not allowed here.

So, I used the -1 trick.

An this was good.

All of a sudden, I had a bad suspicion: what if I put more entries than the number of columns ? (or less ? *)

Used code:

 LB.Heading(-1) = "Character" + Chr(9) + "Story #" + Chr(9) + "Story Title" + Chr(9) + "Date Start" + Chr(9) + "Date End" + Chr(9) + "Size (Bytes)" + Chr(9) + "Kind (Extension)" + Chr(9) + "Comments"

The ListBox had one column less than the number of passed strngs:

Eureka !

No crash: I only lost the definition for the last column (Comments, here).

BTW: I forgot to say that I had a bug in the code far above: there was a case where there was less than 7 columns and I was trying to add a string to a Header column that does not exists ! (thus the Eureka).

FWIW.

  • Less: the language reference says the ListBox will display the default value (usually the Column #).

Often I use something like this.

dim s as String s = "Character,Story #,Story Title,Date Start,Date End,Size (Bytes),Kind (Extension),Comments" LB.ColumnCount = CountFields(s,",") LB.Heading(-1) = s.ReplaceAll(",", chr(9))

You can add headings, cell values, row tags and cell tags for any column number (up to 63) > ColumnCount - 1. AFAIK it is not documented, but has worked that way for years.

I used:

LB.Heading(-1) = "Character","Story #","Story Title","Date Start","Date End","Size (Bytes)","Kind (Extension)","Comments"

but Xojo refused it.

All in all: this is not a problem, but just a way things are done.

Also, the line of code is smaller (1 line) with comma than + Ch(r59) +.

Danke freunds.