Solved

How do I add horisontal scrollbars in c#

Posted on 2006-06-27
5
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

636 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