Horizontal Scrollbar on Listbox Doesn't Work

This seems weird to me. I’m opening a variety of file types: ODBC, CSV, TAB, SQLite, Excel, even Access. Users are supposed to provide a data file for analysis in a particular format: Header row, followed by n data rows. These are essentially database tables, and they get loaded into a SQLite database. My analytics operate on those SQLite tables.

I need to provide a quick eval to the user to ensure that the file user has picked looks like it should. So I’m popping 100 rows into a listbox without formatting, just raw. This is mainly for the delimited text files, I use a different approach for database and Excel files (MBS for that). This works and is easy. The listbox specs include horizontal and vertical scrollbars.

But only the vertical scrollbar shows up. The data look fine but I can’t see the right side of the data. The horizontal scrollbar doesn’t show up. I’ve tried several things, including adding an individual scrollbar, to no avail. Granted the listbox has only one column (a big one) but I still want to scroll to the right.

Do I have to have more than one column or something? What gives?

[quote=96075:@Kenneth Reed]This seems weird to me. I’m opening a variety of file types: ODBC, CSV, TAB, SQLite, Excel, even Access. Users are supposed to provide a data file for analysis in a particular format: Header row, followed by n data rows. These are essentially database tables, and they get loaded into a SQLite database. My analytics operate on those SQLite tables.

I need to provide a quick eval to the user to ensure that the file user has picked looks like it should. So I’m popping 100 rows into a listbox without formatting, just raw. This is mainly for the delimited text files, I use a different approach for database and Excel files (MBS for that). This works and is easy. The listbox specs include horizontal and vertical scrollbars.

But only the vertical scrollbar shows up. The data look fine but I can’t see the right side of the data. The horizontal scrollbar doesn’t show up. I’ve tried several things, including adding an individual scrollbar, to no avail. Granted the listbox has only one column (a big one) but I still want to scroll to the right.

Do I have to have more than one column or something? What gives?[/quote]

  • Add an horizontal scrollbar control to the listbox
  • Make sure the listbox ScrollbarHorizontal is off
  • Add this to the scrollbar :

Sub ValueChanged() Listbox1.ScrollPositionX = me.value End Sub

Now the tricky part : to avoid the lines to be cut with a … at then end, you need to set the width of the column to the maximum length in points of the text you load. And to set the maximum value of the scrollbar to the same amount.

Use Graphics.Stringwidth to find the width in points of the longest string loaded in the ListBox.

and the SUM of the columnwidths MUST exceed the width of the LISTBOX…

there was another posting about this same thing a few months back,

Thanks, guys. Big help.

[quote=96207:@Dave S]and the SUM of the columnwidths MUST exceed the width of the LISTBOX…

there was another posting about this same thing a few months back,[/quote]
And it tooks me time to understand. Sorry Dave for that.

Thank you Dave for your help.

Thanks, Michael. This worked perfectly.

You are welcome :slight_smile:

Hey Guys, an old thread I know - but at least I searched first :slight_smile:

I’ve got the same issue as the OP (single column) and I’m struggling to understand the solution posted.

[quote=96144:@Michel Bujardet]

  • Add an horizontal scrollbar control to the listbox
  • Make sure the listbox ScrollbarHorizontal is off
  • Add this to the scrollbar :

Sub ValueChanged() Listbox1.ScrollPositionX = me.value End Sub
. . . . [/quote]
The bit I don’t understand is the above seems to suggest:
Add a horizontal scrollbar, then turn it off?

Are we saying add the scroll bar in the IDE then turn it off in code?

Add a scrollbar control below the listbox (to use as horizontal scrollbar for the listbox)
Turn the horizontal scrollbar of the listbox off

But I would first check if this is still necessary. Bug might have been fixed.

Thanks Markus.

Now I release what I mis-understood. I missed the word “control” as in, physically add the actual Horizontal Scroll Bar in the IDE Library to the Listbox. I forgot it was even there :frowning:

Well, the issue still hasn’t been fixed in 2016R3 WIN as far as I can tell. Which surprisingly is some 3 or so years ago from the original post, so still a bug.

I’ve decided not to worry about the scroll bar and have gone with a completely different solution. If the user ‘double-clicks’ the cell, then a simple message box will show the contents. Which works fine with this program but may not be workable in other projects in the future. Also, I was thinking of using the double-click event for something else.

Certainly would be good if this just “worked” as it should.

I am usure if the OP question received the correct answer.

Real http://documentation.xojo.com/index.php/ListBox , then http://documentation.xojo.com/index.php/ListBox.ScrollBarHorizontal.

To understand and using few words:
In design mode, set to true (ON) the HorizontalScrollBar Property,
Fill the ListBox.ColumnWidths with a list of defined columns values (like “10,20,30”; no % at all).
(you can read this page to better understand.

In the Listbox, the Horizontal ScrollBar will appears when the sumn of the Listbox columns exceed the Listbox Control Width (otherwise, it would be useless).

If the column width is not a fixed value (integer value), the Listbox will not display a ScrollBar.

That said, you can use a ScrollBar control if this pleased you.

Thanks for your input Emile. What you posted makes no sense to me at all. Sorry.

I’ll check and review tomorrow.

Cheers.

I think what Emile was trying to say relates to what I said above.

A horizontal scrollbar will only appear if the SUM of the COLUMN widths EXCEED the PHYSICAL width of the listbox…
His comment about “no %” also applies to “no *”, because if you use either of those, then the column widths are adjusted to always fit inside the PHYSICAL width (therefore no horizontal scroll is required)

Example

  • you have a listbox with 4 columns, the listbox itself is 200 pixels/points wide
  • each column is 50 pixel/points (50,50,50,50), No scrollbar, the contents FIT 4*50=200
  • but if your widths were 60,60,60,60 then there WOULD be a scrollbar because 4*60=240, and 240 exceeds 200, so the contents must be scrolled to see all of it

Note : this example doesn’t take into account adjustments made interally for the width of the vertical scrollbar etc.

Ta-da !!! . . . finally I see where I went wrong. Thanks Dave, Emile & Markus.

I was using a single column and was just looking at the listbox width itself. I hadn’t noticed the “ColumnWidths” option in the IDE. It now makes sense - if the total column widths doesn’t exceed the listbox width, then there is no need for the horizontal scroll bar to appear.

Therefore I retract what I said previously about “it should just work” - It DOES work, when you understand how. A good days rest from late night programming certainly helped as well :slight_smile:

This is an addition to an old post, but my experience might help someone.
I’ve just spent 3 days trying to figure why my horizontal scrollbar on a listbox wouldn’t work. It was showing up in the IDE but wouldn’t appear on the compiled program.
I was modifying the program to add the horizontal scrolling. I had been saving the column widths and reinstating them next time the program ran. While I had changed the IDE to ensure the total column widths exceeded the listbox width and removed the ‘%’ and ‘*’ options the saved column widths still had them - horizontal scrolling didn’t work.
When I removed the save row from the preference file everything worked as expected.
Only took me 3 days to figure that out!!

Jack

Unfortunately John, you do not asked here, it could have saved you time :frowning:

The answer is here:
http://documentation.xojo.com/api/deprecated/listbox.html#listbox-hashorizontalscrollbar

Yes, reading the LR may save time. :wink:

[quote=462408:@Emile Schwarz]Unfortunately John, you do not asked here, it could have saved you time :frowning:

The answer is here:
http://documentation.xojo.com/api/deprecated/listbox.html#listbox-hashorizontalscrollbar

Yes, reading the LR may save time. ;)[/quote]

The LR states “New in 2019r2

Maybe John is using older Xojo version?

yes this is “NEW” in 2019R2
previous to that it was

same thing different name

New name makes it better :wink:

that WAS scarasm I hope