<p>How can I add horizontal scroll capabilities to the asp.net listbox control?</p>

[{'answer_id': 45549, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 1, 'selected': False, 'text': '<p>If you really, really need it, one idea would be to create a custom\nListBox class whose HTML looks like this: sets the width of the SELECT\nto that of your widest value\'s width (the max width of the scrollbar,\nfor example). Now wrap that SELECT inside of a DIV of the \'constrained\'\nsize and let it scroll on overflow.</p>\n\n<p>Here\'s a quick example starting down those lines, here\'s the type of\nHTML you want spit out by a control:</p>\n\n<pre><code>&lt;div style="width:200px; height:100px; overflow:auto;"&gt;\n&lt;SELECT size="4"&gt;\n&lt;OPTION\nValue="1"&gt;blahblahblahblahblahblahblahblahblahblah blahblah&lt;/OPTION&gt;\n&lt;OPTION Value="2"&gt;2&lt;/OPTION&gt;\n&lt;OPTION Value="3"&gt;3&lt;/OPTION&gt;\n&lt;OPTION Value="4"&gt;4&lt;/OPTION&gt;\n&lt;/SELECT&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>so in essence I\'d recommend creating a composite custom control for\nthis, which renders this HTML. They\'re pretty easy to make, Google on\nthe terms \'composite control asp.net\'.</p>\n\n<p>The toughest part will be matching up the div dimensions to that of the\nselect box, to make the scrollbars work/line up properly. That\'s why\nit\'s kinda tricky.</p>\n\n<p><a href="http://www.velocityreviews.com/forums/t114075-add-horizontal-scroll-bar-to-a-server-control-listbox-or-dropdownl.html" rel="nofollow noreferrer">Source</a></p>\n\n<p>Also, take a look at this: <a href="http://www.freevbcode.com/ShowCode.asp?ID=5362" rel="nofollow noreferrer">Automatically Adding/Hide Horizontal Scroll bar in the ListBox control</a></p>\n\n<p><strong>EDIT</strong>: Make sure you have enough height to include the scroll bar height or else you\'ll get the vertical scroll bar on both controls.</p>\n'}, {'answer_id': 45554, 'author': 'Codeslayer', 'author_id': 4021, 'author_profile': 'https://Stackoverflow.com/users/4021', 'pm_score': 1, 'selected': False, 'text': '<p>We can put this list box inside a DIV and set the style for DIV to overflow which will automatically show the scroll bar whenever necessary.</p>\n\n<p>Your aspx page has the following DIV:</p>\n\n<pre><code>&lt;div id=\'hello\' style="Z-INDEX: 102; LEFT: 13px; OVERFLOW: \n            auto; WIDTH: 247px; POSITION: absolute; TOP: 62px; HEIGHT: 134px" &gt;\n</code></pre>\n\n<p>Put your asp:listbox inside the DIV definition. In page_load function, you need to define the width and height of the list box properly, so that it won\'t overflow with the DIV.</p>\n\n<pre><code>private void Page_Load(object sender, System.EventArgs e)\n{\n    if (!IsPostBack)\n    {\n\n        int nItem = Convert.ToInt32(ListBox1.Items.Count * 17);\n        ListBox1.Height = nItem; \n\n        ListBox1.Width = 800; \n\n    }\n}\n</code></pre>\n\n<p>Code and solution available at <a href="http://www.codeproject.com/KB/custom-controls/HorizontalListBox.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/custom-controls/HorizontalListBox.aspx</a></p>\n'}, {'answer_id': 29523336, 'author': 'Vinicius', 'author_id': 4554703, 'author_profile': 'https://Stackoverflow.com/users/4554703', 'pm_score': 2, 'selected': False, 'text': '<p>Example to add horizontal scroll:</p>\n\n<pre><code>&lt;asp:ListBox ID="List" runat="server" Height="320px" Width="100%" style="overflow-x:auto;"SelectionMode="Multiple"&gt;\n&lt;/asp:ListBox&gt;\n</code></pre>\n\n<p>CSS3 overflow-x Property: <a href="http://www.w3schools.com/cssref/css3_pr_overflow-x.asp" rel="nofollow">http://www.w3schools.com/cssref/css3_pr_overflow-x.asp</a></p>\n'}, {'answer_id': 31075360, 'author': 'Padmanaban', 'author_id': 3753470, 'author_profile': 'https://Stackoverflow.com/users/3753470', 'pm_score': 0, 'selected': False, 'text': '<p>If you are doing it only for display purpose, You can do it in another way by using Textbox with mulitiline property. By appending the text with new line as such!</p>\n\n<pre><code>    List&lt;Yourclass&gt; result = null;\n    result = Objname.getResult(Parameter1, Parameter2);\n    foreach (Yourclass res in result)\n    {\n        txtBoxUser.Text += res.Fieldname1.ToString();\n        txtBoxUser.Text += "\\r\\n" + res.Fieldname2.ToString();\n        txtBoxUser.Text += "\\n\\n";\n    }\n</code></pre>\n\n<p>Hence you will get the view of mulitline textbox with All your data arranged in good format as above code(New line and all). And also it will wrap your texts if it exceeded the width of your textbox. Also you no need to bother about the scrollsbars and here you will get only vertical scroll bar since all our results have been wrapped as per the behaviour of textbox.</p>\n'}]
['https://Stackoverflow.com/questions/45545', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1360/']