Horizontal Scrollbar on Listbox Doesn't Work

  1. 5 years ago

    Kenneth R

    5 Jun 2014 Mission Viejo, CA

    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?

  2. Michel B

    5 Jun 2014 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 5 years ago

    @Kenneth R 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?

    • 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.

  3. Dave S

    5 Jun 2014 San Diego, California USA

    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,

  4. Kenneth R

    6 Jun 2014 Mission Viejo, CA

    Thanks, guys. Big help.

  5. Emile S

    7 Jun 2014 Europe (France, Strasbourg)

    @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,

    And it tooks me time to understand. Sorry Dave for that.

    Thank you Dave for your help.

  6. Kenneth R

    9 Jun 2014 Mission Viejo, CA

    Thanks, Michael. This worked perfectly.

  7. Michel B

    9 Jun 2014 Pre-Release Testers, Xojo Pro RubberViews.com

    You are welcome :)

  8. 2 years ago

    Steve K

    7 Jul 2017 Melbourne, Australia

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

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

    @Michel B

    • 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

    . . . .

    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?

  9. Markus W

    7 Jul 2017 #JeSuisHuman New Zealand, Auc...
    Edited 2 years ago

    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.

  10. Steve K

    7 Jul 2017 Melbourne, Australia
    Edited 2 years ago

    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 :(

    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.

  11. Emile S

    7 Jul 2017 Europe (France, Strasbourg)

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

    Real http://docs.xojo.com/index.php/ListBox , then http://docs.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.

  12. Steve K

    7 Jul 2017 Melbourne, Australia

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

    I'll check and review tomorrow.

    Cheers.

  13. Dave S

    7 Jul 2017 San Diego, California USA

    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.

  14. Steve K

    8 Jul 2017 Melbourne, Australia

    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 :)

  15. 5 days ago

    John A

    Nov 8 Glasgow, Scotland

    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

  16. Emile S

    Nov 8 Europe (France, Strasbourg)

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

    The answer is here:
    http://docs.xojo.com/ListBox.HasHorizontalScrollbar

    Yes, reading the LR may save time. ;)

  17. brian f

    Nov 8 Pre-Release Testers, Xojo Pro Chilly California

    @Emile S Unfortunately John, you do not asked here, it could have saved you time :(

    The answer is here:
    http://docs.xojo.com/ListBox.HasHorizontalScrollbar

    Yes, reading the LR may save time. ;)

    The LR states "New in 2019r2"

    Maybe John is using older Xojo version?

  18. Dave S

    Nov 8 San Diego, California USA
    Edited 5 days ago

    http://docs.xojo.com/ListBox.HasHorizontalScrollbar

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

    http://docs.xojo.com/ListBox.ScrollBarHorizontal

    same thing different name

  19. brian f

    Nov 8 Pre-Release Testers, Xojo Pro Chilly California

    New name makes it better ;)

  20. Newer ›

or Sign Up to reply!