Page 1 of 1

Listbox advice

Posted: Sunday 10th January 2021 2:21am
by AndyGable
Hi Everyone,

I have been working on my small project and I think I could do with some guidance

what I have at the moment is this

Image
when something is added to the listbox and this is fine but when I add something that has 2 lines in it i get this


Image
how do I get it so it displays right also how do I have it always with the blue Line? ( like below)

Image

Re: Listbox advice

Posted: Sunday 10th January 2021 5:21am
by Godzilla
Hello Andy,

The problem you're having with the display of the text in your second image is: the text string that's been scanned into your ListBox contains an ASCII code for either a carriage return (gb.Cr) or a line feed (gb.Lf). Perhaps even both (gb.CrLf). This crams two lines of text into a vertical space designed for only one line of text.

I'd use the Replace() function, which will clean any of those three ASCII codes from the text string if they're present (because we don't know which one it is), allowing it all to be on the same line, separated by a dash character.

In my code example below, I'll clean any of those ASCII codes from the text already present at index zero in the ListBox. But its always better to clean these codes from the source string, before it gets assigned to the ListBox. Depending on how your code works, it may simple. Or it may be simpler to fix what's already in the ListBox.

Here's the code:

ListBox1[0].Text = Replace(ListBox1[0].Text, gb.Cr, " - ")
ListBox1[0].Text = Replace(ListBox1[0].Text, gb.Lf, " - ")
ListBox1[0].Text = Replace(ListBox1[0].Text, gb.CrLf, " - ") 
ListBox1[0].Selected = True

This code will also select that same line, giving it the blue line you wanted. To allow multiple lines in the ListBox to be selected, I believe you'll need to set its "Mode" option to "Multiple", otherwise leave it on "Single".

I hope this helps. Good luck,
Godzilla

Re: Listbox advice

Posted: Sunday 10th January 2021 8:08pm
by AndyGable
Hi Godzilla,

Thank-you for the information that help the problem is the 2 lines should be displayed (i am adding the Crlf myself. how would i widen the area so it displays correctly?

i would need it to show

CADBURYS CREAM EGG
5 @ £0.50

Sorry maybe I did not explain what I wanted clearly (it was 2am when I typed that post)

Re: Listbox advice

Posted: Sunday 10th January 2021 8:56pm
by stevedee
AndyGable wrote: Sunday 10th January 2021 8:08pm ...i would need it to show

CADBURYS CREAM EGG
5 @ £0.50
Hi Andy, I wonder if a ListBox is the best choice for your application.
Have you considered using a GridView or a TableView?
TableView2.png
TableView2.png (15.67 KiB) Viewed 4185 times
TableView.png
TableView.png (17.15 KiB) Viewed 4185 times

Re: Listbox advice

Posted: Monday 11th January 2021 3:22am
by AndyGable
i have tried all the other interfaces before I have even tried to use a group of labels for the display but that looked even worse.

I have had good feed back from customers who say the Listbox is the best for them when they are using the software

The 2 or more line description is only ever used on qty or price override modes so they are not very often used.

I am open to advice though all my other window applications use the list box to display product data (as the list box is used to populate the printed receipt (on the windows version) so if a item is removed / voided it will not print on the receipt

Re: Listbox advice

Posted: Monday 11th January 2021 9:01am
by stevedee
AndyGable wrote: Monday 11th January 2021 3:22am ...I have had good feed back from customers who say the Listbox is the best for them when they are using the software...
I'm sorry, I really don't understand what you are saying. The end user will be unaware of the type of control you are using; they are only interested in its appearance and usability.

The point about using (say) a TableView is that you can control the cell height and therefore include multiple lines of text without the text being cropped. My example didn't show the grid lines, but obviously these can be turned on or off.

I didn't include any of my code because it was so horrible, but I displayed multi-lines like this:-
TableView1[0, 0].Text = "Cadbury Cream Eggs" & gb.Lf & Space(4) & "5 @ £0.50"
If you wanted to keep the Item separate from the cost, then the second example does this;
  TableView1[0, 0].Text = "Item"
  TableView1[0, 1].Text = "Cost"
  TableView1[1, 0].Text = "Cadbury Cream Eggs"
  TableView1[1, 1].Text = "5 @ £0.50"
  TableView1[2, 0].Text = "Orange Juice - Value"
  TableView1[2, 0].Text = "1l @ £1.50"
...but I'm probably missing your point.