none
VB.NET Horizontal Listview Scrollbar RRS feed

  • Question

  • How can I create a horizontal listview scrollbar when the data is too large to fit the width of the listview control on my VB.NET form?  The data is stored in a separate location.  I could shorten the number of characters in the data (in this database in a separate location), but it would be nice when the larger data is shown on the listview control, that we could horizontally scroll over to the right to view all of the characters.

    Setting the listview property Scrollable = True does not work entirely.  When there's more line items (vertically of this data) that would fit in the listview control then both the vertical and horizontal scrollbars appear.  But if there are not enough line items in this control to activate the vertical scrollbar then the horizontal scrollbar does appear either.  In other words, I get either both the vertical and horizontal scrollbars or none at all.

    I'm curious about any answers with this listview control.  Now if another control is better, then that's an option too.  But since I'm familiar with the listview control and that is what I'm currently using, I was hoping for an answer for that one first.

    One more...I can't just click on the data on the listview to view the characters on the right with the keys, for I programmed it to put that data in another place when clicked.  That's why I would like the horizontal scrollbar.

    I'm using Windows 7 and VB2010 Express.  Thanks.  I appreciate your help.

    Monday, October 9, 2017 6:30 PM

Answers

  • Hi

    I would imagine that the answer would depend on how you have set up/used the ListView.

    For example, I have set up a default ListView, set the View to Details, added one column and set its width to 1000. Added a bunch of long strings to it. When running, a horizontal scroll bar is automatically added.

    Different set ups will not necessarily show the same behaviour though.

    The nature of a ListView, having the scope to display data in many different ways, makes a horizontal scroll bar supefluous in many of them.


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, October 9, 2017 7:10 PM
    • Marked as answer by RichVBNET Monday, October 9, 2017 8:17 PM
    Monday, October 9, 2017 7:10 PM

All replies

  • Hi

    I would imagine that the answer would depend on how you have set up/used the ListView.

    For example, I have set up a default ListView, set the View to Details, added one column and set its width to 1000. Added a bunch of long strings to it. When running, a horizontal scroll bar is automatically added.

    Different set ups will not necessarily show the same behaviour though.

    The nature of a ListView, having the scope to display data in many different ways, makes a horizontal scroll bar supefluous in many of them.


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, October 9, 2017 7:10 PM
    • Marked as answer by RichVBNET Monday, October 9, 2017 8:17 PM
    Monday, October 9, 2017 7:10 PM
  • Now if another control is better, then that's an option too.
    A DataGridView is a much better option, including the fact that it has a .DataSource property to help with binding.

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, October 9, 2017 7:37 PM
  • Les, thanks.  That works. I only am programming part time, so I had to remember what I had done previously (like occasionally about three or four times a year).  I started with a treeview control on the VB form (on the left side).  Then when something is picked from there, I programmatically added a column each time with a header label (to the listview control on the right side).  It's there that I set the column width.  I had forgotten why I picked a column width of -2.  I still don't remember why.  But I changed it for this instance to 800.  But I still needed a little more room so I picked 1000 (which coincidentally is the same number that you wrote about).  Then I was able to get my horizontal scroll bar because the 1000 width was larger than the listview control.  I'll go through the rest of my code and adjust it where required.  Yes you are right that a horizontal scrollbar for all of them could be superfluous.  It's only needed in certain cases where the data string is quite long.  This makes it so much nicer.  Thanks again.

    For those that might be interested...programmatically to add listview columns the code is something like this (as a sample):  I believe there's other varieties to this also, but that is what worked for me.

    Me.lsvNameOfListView.Columns.Add("NameOfHeader", 1000, HorizontalAlignment.Left)


    • Edited by RichVBNET Tuesday, October 10, 2017 1:50 PM
    Monday, October 9, 2017 8:39 PM
  • Frank, I was running late yesterday and I didn't get a chance to reply to you right away. I wanted to thank you for answering this for me. I had put the DataGridView on another control tab for me to use as an experiment. But the treeview and listview controls together work best for me at this time. See my reply to Les yesterday.

    Again, thanks.  I am always open for new ideas; sometimes they work and sometimes they don't work but we never know until we push the boundaries to learn new concepts.

    Tuesday, October 10, 2017 1:38 PM
  • Frank, I was running late yesterday and I didn't get a chance to reply to you right away. I wanted to thank you for answering this for me. I had put the DataGridView on another control tab for me to use as an experiment. But the treeview and listview controls together work best for me at this time. See my reply to Les yesterday.

    Again, thanks.  I am always open for new ideas; sometimes they work and sometimes they don't work but we never know until we push the boundaries to learn new concepts.

    I don't sell them so I don't have a stake in this. ;-)

    A DataGridView has many more options for formatting that a ListView does. As an example in what you said you want to do here, instead of a long horizontal scroll, with a DGV you could alter the row height and for the cell that has a lot of text, set it to wrap. I think that would be more convenient to the user than scrolling.

    To each their own though. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, October 10, 2017 2:38 PM
  • Thanks Frank; that sounds cool.  If I have time later, I'll have to see if I can use DataGridView instead of ListView.  It will be another one of my experiments.  Programming can constantly evolve from one thing to another, as we look for the optimum results. :)
    Tuesday, October 10, 2017 7:56 PM
  • Thanks Frank; that sounds cool.  If I have time later, I'll have to see if I can use DataGridView instead of ListView.  It will be another one of my experiments.  Programming can constantly evolve from one thing to another, as we look for the optimum results. :)

    I don't know what you're working on but a DGV really is a much better control than a ListView.

    Let me know if you run into a problem with it. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Tuesday, October 10, 2017 8:37 PM