Listboxes, clipboard and EndOfLine issues

I was looking at ways to make it easy to copy between 2 listboxes.

I found here what it looks like a good way to do it. The problem is that I get the following:

I have a listbox that sometimes the cell content is multiline (2 lines at most). I have code on CellBackgroundPaint (handle the alternate color) and CellTextPaint (to draw the text correctly when it is 2 lines).

The code used to copy the rows (I put that on listbox1 DoubleClick) is the one listed on the other thread:

Listbox2.AddRow "" Listbox2.cell(Listbox2.LastIndex,-1)= Me.cell(Me.ListIndex,-1)

With this code it works:

Listbox2.AddRow "" Listbox2.cell(Listbox2.LastIndex,0)= Me.cell(Me.ListIndex,0) Listbox2.cell(Listbox2.LastIndex,1)= Me.cell(Me.ListIndex,1)

Why the original code doesn’t work? I thought that lb2.cell(x,-1)=lb1.cell(y,-1) internally is like lb2.cell(x,0)=lb1.cell(y,0) and lb2.cell(x,1)=lb1.cell(y,1). I guess it doesn’t like the EndOfLine that is on the first cell.

I believe when you use (-1), what really happens is the TEXT in the row or column is transfered and reparsed… it does not reiterate thru the cells and move it one by one, which is what you did in your second example

so the first way… it ended up with “11112222” which then got truncated during the move

Thank you Dave.

Because I can’t use the (-1), do you think is better to use the code like that or change it to:


It looks like:

Listbox2.cell(Listbox2.LastIndex,-1)= Me.cell(Me.ListIndex,-1)

doesn’t like that I have EndOfLine.UNIX in the cell.

Did a test with clipboard:

Dim c As New Clipboard c.Text = Me.cell(Me.ListIndex,-1) Listbox2.AddRow Listbox2.cell(listbox2.LastIndex,-1) = c.Text c.Close

And it works. The difference? The clipboard change the EndOfLine.UNIX to EndOfLine.Macinthosh

Don’t know if this is the correct behavior but it is not what I expected.

Reading about EndOfLine, I see:

[quote]EndOfLine on macOS
NOTE: Starting with 2013r1, EndOfLine returns EndOfLine.Unix on all macOS apps.
This change was necessary because 2013r1 creates Cocoa apps by default and Cocoa works with the Unix line endings.
If you require the old behavior, you should explicitly use EndOfLine.Macintosh.[/quote]
So why the clipboard changed the EndOfLine.Unix to EndOfLine.Macintosh?
Maybe the clipboard and the cell (-1) code need to be updated?

Ok, so I did a test on mac, textarea uses chr(10) (0A) and when copied to clipboard is changed to chr(13) (0D).

Now tested on windows, uses chr(13) for both textarea and clipboard.

Yeah, I’m going crazy. I tested this:

TextArea1.Text = "1" + EndOfLine.Windows + "2"

Mac: 310D 0A32
Windows: 310D 32

Now (button action):

Dim s As String = "1" + EndOfLine.Windows + "2"

Mac: 310D 0A32
Windows: 310D 0A32

At last:

Dim s As String = "1" + EndOfLine.Windows + "2" TextArea1.Text = s
Mac: 310D 0A32 for both
Windows: 310D 32 for TextArea1.Text and 310D 0A32 for s

And now using EndOfLine.Windows and the clipboard:

Dim s As String = "1" + EndOfLine.Windows + "2" TextArea1.Text = s Dim c As New Clipboard c.Text = s Dim s2 As String = c.Text c.Close
s2 on Mac: 310D 0D32
s2 on Windows: 310D 0A32
s2 on Linux: 310D 0A32

and changing the code (1 line) to:

c.Text = TextArea1.Text

s2 on Mac: 310D 0D32
s2 on Windows: 310D 32
s2 on Linux: 310D 0A32

Edit: remote tested on Linux Mint and added above
Edit2: I hope someone will understand my information

Until your Listbox displays multiple lines of text in a single Row, you will have “visual” troubles.

Make the ListBox Editable and make your tests then.

Or add a TextArea and copy the selected Row contents into the TextArea to watch how your copied text is.

Thank you Emile. Sorry, I think I jumped from one thing to another then another. I’ll try to post all the problems here, I think they are related (a little).

1.- this code doesn’t work if I use chr(10) as EndOfLine on listboxes with multiline cell, but works if chr(13) is usedl:

Listbox2.AddRow "" Listbox2.cell(Listbox2.LastIndex,-1)= Me.cell(Me.ListIndex,-1)

2.- when something is copied to the clipboard on a mac if the EOL is chr(10) then it is changed to chr(13). EndOfLine.Windows is chr(13)+chr(10) but when copied to the clipboard (on a mac) it is changed to chr(13)+chr(13)

3.- using EndOfLine.Windows on Windows you usually get chr(13)+chr(10) but when you do a TextArea.Text = String then chr(10) is lost, so you only get chr(13)

What I expected:

  • if I use chr(10), a) the lb.cell(x,-1) should work and b) do not change to chr(13) when copied to the clipboard
  • if using EndOfLine.Windows, always have chr(13)+chr(10) (just like my latest test with Linux)

I hope this is more clear.

Do you know of ReplaceLineEndings ?

In 20 years of use of this IDE, I never used EndOfLine..

Also: Listbox2.AddRow have many syntax(es ?)… and some do not need two or more lines to fill a Row at once (using a comma as delimiter, Split, etc.)

Thank you Emile.

Yes, I have used ReplaceLineEndings, but how you never used EndOfLine. when the example show:

Dim s As String s = ReplaceLineEndings(TextField1.Text, EndOfLine.Windows)

Do you only put EndOfLine there and let Xojo add the EndOfLine for each platform? (Unix for Mac and Linux and Windows for Windows)

I did a test with this code:

Dim s As String = "1" + EndOfLine + "2" TextArea1.Text = s Dim c As New Clipboard c.Text = TextArea1.Text Dim s2 As String = c.Text c.Text = ReplaceLineEndings(c.Text,EndOfLine) Dim s3 As String = c.Text c.Close

On Mac (using the hex values to see the differences):

  • s = 310A 32
  • s2 = 310D 32
  • s3 = 310D 32
    in this case, ReplaceLineEndings can’t change 0D back to 0A for clipboard

On Windows:

  • s = 310D 0A32
  • s2 = 310D 32
  • s3 = 310D 0A32
    in this case, ReplaceLineEndings fixed what the clipboard had (could be a clipboard bug?)

On Linux:

  • s = 310A 32
  • s2 = 310A 32
  • s3 = 310A 32
    in this case, there is no need to use ReplaceLineEndings because the clipboard didn’t change the LineEnding. This is what I expect on Mac and Windows.

I think there is an issue with EndOfLine.


I do not saw any, but I may be wrong.

Because I get an advice that do not display the one you refer to. :wink: And that example worked fine, so I never try anything else.

For Listbox with many lines in a Row (a Cell with many Lines): I know only one ine is displayed by default and do accordingly. If I have to display many lines in a Cell, I made a copy of the text in a TextField (with many lines set ON).

Have a look at Feedback Release Notes: select one Row and read how it is displayed when there is more than one line in a Cell (there are examples).

I am sorry to not be helpful enough.

Thank you for your time Emile.

I visited the Feedback Release Notes, almost all cells that don’t fit the space are single line. I found for 2017r3 case id 49039 as one with an EndOfLine, but I can’t know if it is using chr(10), chr(13) or both (I think it will look the same no matter which).

I understand this “issue” is minor because it works as expected (at least it looks like that) visually. In other words, if I have a multiline TextField or TextArea with chr(10) copy that to clipboard (changed to chr(13)) and then I paste that again on another TextArea it will look the same. I may file a bug report.

Look at 2017r3 Release Notes:

	CHANGE	47859	Framework » All	Add new Drag events to the Listbox, changes include:

I removed all other lines (they are a ton or more !).

Only the firt line is displayed (or part of the first line), the remainder is displayed in the TextArea, below the Listbox.

In a project, I have three (or four ?) columns that may have 3 or more lines… They are accessible in vew by Card (All fields in a window), and when I print them (as PDF)… Short: no trouble at all.

That application runs in both Windows (7) and macOS (many different versions).

Thank you Emile, yes I understand and is a good idea to do. I found case 47859 under 2017r2 Release Notes.

For my little program, I limit the number of lines for the cell to 2 and I put this under Listbox CellTextPaint:

For i As Integer = 0 To 1 g.DrawString(arr(i), x, y - g.TextHeight / 2 + i * g.TextHeight) Next

I definitely will use your recommendation when I need to code something without a set number of lines.

Some people are able to display more than one line in a Cell / Row. Because I do not need this feature, I do not follow that path.

Nota: the RowHeight property can be changed, but ASAIK, this is for each and every Row.

Yes, the RowHeight is for each/every Row. You can see that on the image I posted (first column). I changed the Height to be able to display 2 lines.

My code detects if there are 2 lines or only 1. If there are 2, then the first line is drawn half the text distance above what normally will draw, and the second line half the text height below. That way it looks right. If there is only 1 line, then it is draw as default on the middle of the cell.

For me it looks good enough.

OK, nice.