Solved

How do I add horisontal scrollbars in c#

Posted on 2006-06-27
5
341 Views
Last Modified: 2008-01-09
Hi.

I´m having problems adding horisontal scrollbar in my 'asp:listbox'.

And by the way, my vertical scrollbar doesn´t show up, I thought
they showed automaticly.
0
Comment
Question by:jenniferw
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:five22bags
ID: 16992052
The vertical one should show up if you set TextMode="MultiLine" within your <asp:TextBox>.

I have never seen or heard of an asp:textbox with a horizontal scrollbar.
0
 

Author Comment

by:jenniferw
ID: 16992103
Well you see, my listbox width is smaller than the filenames in showed the listbox, and I
want the user to be able reading this filenames, thats why the horisontal scrollbar is so
interesting. I don´t want to change the size of the listbox width, and thereby destroy my
layout...
0
 
LVL 11

Accepted Solution

by:
five22bags earned 500 total points
ID: 16992966
Wow, I sincerely apologize for not reading more carefully.... LISTBOX not TEXTBOX.

Horizontal scrollbars are actually a limitation of HTML, rather than ASP.NET. To trick the HTML, you will have to put your listbox inside of a DIV element. You can copy and paste the following code to see what I mean:

<div id='hello' style="Z-INDEX: 102; LEFT: 13px; OVERFLOW: auto; WIDTH: 247px; POSITION: absolute; TOP: 62px; HEIGHT: 134px" >
                        <asp:ListBox id="ListBox1" runat="server" Width="400px" Height="134px" BorderStyle="None">
                              <asp:ListItem Value="This is a very very very very very very very very long product">This is a very very very very very very very very long product</asp:ListItem>
                              <asp:ListItem Value="Computer">Computer</asp:ListItem>
                              <asp:ListItem Value="Monitor">Monitor</asp:ListItem>
                              <asp:ListItem Value="Keyboard">Keyboard</asp:ListItem>
                              <asp:ListItem Value="oops">oops</asp:ListItem>
                              <asp:ListItem Value="oops">oops</asp:ListItem>
                              <asp:ListItem Value="oops">oops</asp:ListItem>
                              <asp:ListItem Value="oops55">oops55</asp:ListItem>
                              <asp:ListItem Value="oop6">oop6</asp:ListItem>
                        </asp:ListBox>
                  </div>



Essentially, the scroll bars created here are actually the DIV scroll bars, and not the Listbox scrollbars. If the listbox is not tall enough (height), you will see TWO vertical scroll bars if you were to pan all the way over with the horizontal one. In the example I have given you, it does just that. To correct that, to prevent two vertical scroll bars, you have to set the height of the LISTBOX element (not the DIV element) to be tall enough to see all of the items. You also may want to consider re-sizing the LISTBOX on Page_Load to set the height to exactly the amount of items in the LISTBOX.

0
 

Author Comment

by:jenniferw
ID: 16993018
Thank´s for helping me out on this problem!
0
 
LVL 11

Expert Comment

by:five22bags
ID: 16993075
That is the auto-resize code.
You can use something similar to resize for the width; remember that the width of the ListBox WITHIN the DIV element must be wide enough to view the entire item text, whereas the width of the DIV can be as small as you want it (to create the horizontal scroll).

private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!IsPostBack)
                  {
                        //Load all items in the list box.
                        int nItem = Convert.ToInt32(ListBox1.Items.Count * 17);
                        ListBox1.Height = nItem; //Set height depends on the font size.
                        ListBox1.Width = 800; //This will ensure the list item won't be shrinked!
                  }
            }
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A short article about a problem I had getting the GPS LocationListener working.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now