A brand new ListBox (cosmetic) bug

Xojo current (as today)
OS X 10.9.3 (France)
MacBook Pro 2011-11

The project loads a text file and compute by itself the number of Columns at load time (I forgot how).

Depending on the loaded text file contents, you may have a « spurious, useless » column (last column).

At debug time (debug for the said text file), I may have a misplaced Tab in one or many lines; if so, I will have an extra (or more) and unwanted column(s).

To know how many of these lines that have one or more unneeded Tab characters, I need to sort that (these) column(s). Then, I go back to the text file and remove the unneeded Tab.

Then, I go back to my window and load the corrected text file.

Because I do not click in a different header (I think), the now removed Column is still here and activated.
Oh, if you close the window / re-open it and re-load the last text (or one text file), the bug disappears.
When the bug is visible, a window resize (and so the ListBox), the bug stays visible.

A click in another Heading Column “disable” the dug.

Watch carefully the screen shot below.

BTW: I used a loop to read one line at a time (of a Tab Tab Return file) and add the line using the -1 trick.

Because I am in the process of changing my internal hard disk, I do not really know where that project is / unable to provide the real used code, but I feel that it is easy to check that.

The new text replace the previous ListBox contents, so I use DeleteAllRows before entering in the loop that reads the lines from the file and add Rows into the ListBox.

BTW: during the previous bug squash, this was probably (maybe) not seen.

Did you file a feedback case?
No attached screenshots (as you referred there were.)

Does your code remove all the columns before it tries to load up the new text file, because this is where it sounds like the problem is. DeleteAllRows won’t remove columns. If you are still having troubles, try throwing in a Listbox.refresh before loading the new data - this could help.

Feedback: no
Delete: I use DeleteAllRows
Screen shot: I certainly forgot. Here we are:

Nota: this is a cosmetic bug that is removed once you click in a valid heading button.

Do you set at some point the ColumnCount to zero? This will not work, because a listbox always needs at least one column.

This is what happened to me at some point:

lbx.ListCount = 10 // there are now 10 columns lbx.ListCount = 0 // there is now 1 column For i As Integer = 0 To 4 // adding 5 columns in a loop lbx.ListCount = lbx.ListCount + 1 Next // there are now 6 columns instead of the anticipated 5

To further reiterate:

When you DeleteAllRows immediately follow this with a calculation of the number of columns you need and set the Listbox ColumnCount to that value. All should then be good when you re-populate the Listbox.

Remember that ColumnCount is 1-based.

Simon,

you mean that my code is buggy ?

I will search a bit more about that project or rewrite that part from the start and be back by Monday.

Potentially all code is buggy!

Hope you get on ok and waiting to hear your results.

Here I am. I wrote the whole lot from scratch and get troubles to display the bug but I found a way.

To do that, take a multi Tab lines of text file,
add one extra tab at the end of one line,
Load the file
click in the last column (empty)
Remove the extra tab and save the file
load the modified file
Watch the extra Column with a selected Heading: resize the window to see it, eventually.

The code to use (parts comes and are adapted from the Language Reference):

[code] Dim OpenDlg As New OpenDialog
Dim OpenFI As FolderItem
Dim OpenTIS As TextInputStream
Dim LocRow As Integer

// Ask the user to choose a text file
OpenDlg.InitialDirectory = SpecialFolder.Documents
OpenDlg.Title = “Select a TEXT file”
OpenDlg.Filter = FT.Text
OpenFI = OpenDlg.ShowModal()
If OpenFI = Nil then
// User Cancelled
Return
End If

// Clears the ListBox
LB.DeleteAllRows
LB.ColumnCount = 1 // This line is important, why ?

// Read the selected TEXT file and put it into the ListBox
Try
// Get a TextInputStream reference
OpenTIS = TextInputStream.Open(OpenFI)

// Loop thru the file Read // Add all lines
While Not OpenTIS.EOF
  LB.AddRow ""
  LocRow = LB.LastIndex
  LB.Cell(LocRow,-1) = OpenTIS.ReadLine
Wend

Catch e As IOException
OpenTIS.Close
MsgBox(“Error trying to access the file.”)
End Try

OpenTIS.Close
OpenTIS = Nil
[/code]

Is that within you application or manually in NotePad, TextEdit or so?

Hi Eli,

thanks for your answer.

However, I do not really understand the question.

The text file was created in OS X TextEdit. Each line have different data separated with a Tab and ending with a CR (ReadLine read just one line).

I do not think it have to do something with the external application used to generate the Text file (it could have been done with a Xojo created text editor).

The wolf is in Xojo ListBox as the code demonstrate it.

Nota: it may be obvious, but LB is a reference to the main (and only) window.

I quoted you and said I don’t understand this line:

[quote=103417:@Emile Schwarz]To do that, take a multi Tab lines of text file,
add one extra tab at the end of one line,
Load the file
click in the last column (empty)
Remove the extra tab and save the file <------- who is doing that, your app or do I do that in TextEdit.
load the modified file
Watch the extra Column with a selected Heading: resize the window to see it, eventually.[/quote]

I haven’t dissected your code, but if I understand you correctly, you are saying that when you assemble your string, sometimes you get
DATA tab DATA tab DATA tab DATA
and sometimes you get
DATA tab DATA tab DATA tab DATA tab

If so, why not check if RIGHT(my string,1) is the tab character, and if so, make
mystring = left(my string,len(my string)-1)

then create a listbox row from it?

If the number of columns is more variable than that, maybe use split to get the fields, then assemble them into a new string with exactly the number of columns you want?

I’m seeing it. My code is…

[code] Listbox1.DeleteAllRows
Listbox1.ColumnCount=1

Listbox1.ColumnCount=ubound(TextField1.Text.Split(chr(9)))+1
Listbox1.AddRow “”
Listbox1.cell(0,-1)= TextField1.text[/code]

enter DATA tab DATA tab DATA tab
creates 4 columns as expected. click the 4th header. Remove the 4th tab… now the listbox displays 4 columns and a little ghost header for the now removed 4th column (it is selected)

Looks like it’s just related to ColumnCount excluding the previously selected column…

[code] Listbox1.DeleteAllRows
Listbox1.ColumnCount=1

Listbox1.ColumnCount=val(TextField1.Text)
Listbox1.AddRow “”
[/code]
can reproduce it too

Set SortedColumn to -1.

  Listbox1.DeleteAllRows
  Listbox1.ColumnCount=1
  Listbox1.SortedColumn= -1

  Listbox1.ColumnCount=val(TextField1.Text)
  Listbox1.AddRow ""