Listbox: working with Cells

The current project ask the user for a folder,
get each item found in that source folder
report some properties (name *, file size and file extension),
the number of fields in each file nae can be (and is) variable and of course unknow at run time.

But, this we do not care (of the number of columns in this Listbox because it never goes very far (usually around 10-15).

Then, I falled into a first trap: if I do not set the Columns widths. My first write falls into a trap: OutOfBoundsException here:

LB.Column(Cell_Idx).WidthExpression = "100"

Example of actual code:

[code] For Cell_Idx = 0 To Field_Cnt
Dim One_Field As String

    // a. Get one field
    One_Field = NthField(File_Name, Field_Del, Cell_Idx + 1) // Field_Del = " - ", the file name delimiter
    // b. Set the field in a Cell
    LB.Cell(LocRow,Cell_Idx) = One_Field // Cell_Idx is the Column number
    // c. Set the Column Width
    LB.Column(Cell_Idx).WidthExpression = "100" // Cell_Idx have the same value as above !
    // The OutOfBoundsException appears in the line above !
    // d. Set the Header
    LB.Heading(Cell_Idx) = "Column " + Str(Curr_Col)

The code scans the file name and extract each field into a different cell / Listbox

After many hours of search, test and tries, I discovers that you can add text to a non existent column (Cell), but you cannot set its width using LB.Column(Cell_Idx).WidthExpression = "100" (for example). Weird.

This recalls me the Listbox -1 bug report. In the -1 case, I do not care since it is in the documentation and I recall it (was it here since REALbasic 1, 20 years ago ?)

  • I “split” the file names using a delimiter and put all fields into a different Cell.
    ** The documentation wrongly says that you have to add a column before been able to write in a Cell from that Column. It is false. You have to change the number of columns to be able to display that amount of columns.

Say you have a Listbox with 12 columns and you populate it. In the last two columns, you put service data you do not want the user to be able to see them. Just set Listbox1.ListColumn to the actual number of columns - 2 and the last two columns will not be displayed.

You can create a method in a module to hide a Column

Public Sub HideColumn(extends source as listbox, col as integer) source.Column(col).WidthActual = 0 End Sub