 |
|
 |
Shiby, Your script is wonderful. I tried customizing the same for only drop down list(combo box) and tried to get horizontal scroll bar. Some how it is not working. Can you let me know how to do this. Also is it possible to get the tool tip for the selected option?
Nags
|
|
|
|
 |
|
 |
The only problem I have with this is that there is an extra vertical scrollbar, and I don't want this scrollbar. I have to scroll the the right to view the real scrollbar...which is non-intuitive. Any way around this? Thanks
|
|
|
|
 |
|
|
 |
|
 |
Thank you for publishing this article, but I'm so new to ASP.NET and all of this that I don't know how to install the files so I can view the demo. In the future it would be very nice if you could include this information in the article.
Since I haven't been able to try out the demo, I'm curious if in ComboBox mode if it will support a TextBox of a specific width and a drop down list box of another width and height, hopefully, that can also be specified.
My need for this comes from the lack of space on my form. While I need the ability to type in new text that isn't on the list, I recently tried experimenting with the regular server side drop down list control by connecting the onFocus and onBlur event hooks to a javascript function that makes the drop down list larger when it was selected. Unfortunately, this caused problems because the adjacent drop down list components would show through when they were overlapped, and when the drop down list was selected for the first time it would forget the selected item and show a blank, even though there wasn't a blank item in the list. So my hope is that your control will solve these problems.
|
|
|
|
 |
|
|
 |
|
 |
what ever div you have used, cann be applied only to the list boxes. my problem is iam using a dropdownlist
here is my code <asp:DropDownList ID="tds" Runat="server"> <asp:ListItem>St. Joseph's College, Bangalore <asp:ListItem>ISRO Telemetry Tracking Command Network (ISTRAC),Bangalore
so now on click of that dropdownlist i can see a list of items which will be listed in the right side without a horizontal scroll bar, but my dropdownlist is cutting in its edge. i want something like this in dropdownlist pls help me asap
|
|
|
|
 |
|
 |
sorry my code wasnt pasted completely
<asp:DropDownList ID="tds" Runat="server"> <asp:ListItem>St. Joseph's College, Bangalore</asp:ListItem> <asp:ListItem>ISRO Telemetry Tracking Command Network (ISTRAC),Bangalore</asp:ListItem> </asp:DropDownList>
|
|
|
|
 |
|
 |
Hey Guys -
I found another problem 
I have this listbox that I am dynamically populating. In some cases there is going to be very long option text. ie. 200 chararacters and only 100 are visible (so I need the scroll bar). But in other cases that same listbox will be populated with options where the biggest is 25 chars long.
Basically... when the thing loads its really weird because the listbox isn't as long as the div. (do you know what I mean? - try removing all the really long text items from the default list and replace them with really short text items).
I am trying to figure out how to force the listbox to be at least 304px in width. Keep in mind when I give it a fixed width of 304px that won't work because I will lose horizontal scrolling. There is some min-width property in CSS that IE 6 doesn't support so that idea is bust too. So yeah.... I am trying to figure out how to simulate a min-width CSS attribute through javascript.
Hopefully you guys know what I mean. I'll post a solution if I figure it out but so far I have spent like 3 hours on this and couldn't solve it and I am giving up for now...
|
|
|
|
 |
|
 |
Hi there,
I am facing the exact same problem. Anybody has found the solution?
Regards, Frederic
|
|
|
|
 |
|
 |
Shiby, Great approach to this issue. I tweaked the functions to make them generic and to solve the issue of the select box scrolling back to the top when an option originally hidden from view is selected.
I've very new to writing javascripts, so feel free to let me know what you think. If you find this useful, feel free to share it.
function OnDivScroll(listObj,listSize){ if (listObj.length > listSize){ listObj.size=listObj.options.length; } else{ listObj.size = listSize; } }
function OnSelectFocus(listObj,divObj,listSize){ var lastScrollPos = divObj.scrollTop; if (divObj.scrollLeft != 0){ divObj.scrollLeft = 0; } if( listObj.options.length > listSize){ listObj.focus(); if(listObj.value==''){ listObj.size = listSize; } else{ divObj.scrollTop = lastScrollPos; } } }
Pat
|
|
|
|
 |
|
 |
Thanks Pat  I'll update this article along with your tweaked function to overcome some limitations in some days. Once again thanks for yor efforts 
Thanks & Regards, Shiby
-- modified at 3:41 Tuesday 21st February, 2006
|
|
|
|
 |
|
 |
This is probably the best 'attempt' at a scrollable ListBox I have seen yet. In my opinion, there are two things that you still need to solve.
a.) If you have 30 items in the list... and you scroll to the 30th item... when you click to select it the listbox will suddenly jump to the very top. This is not intuititive.
b.) When you have 30 items in the list... just after the page loads... whne you click the scroll bar to scroll to the bottom... the size of the scroller suddenly get's a lot smaller. (which is weird).
Let me know if you've put any thought into these hurdles.
-Trevor
|
|
|
|
 |
|
 |
Tboner, I was able to solve issue (a) by tweaking the OnSelectFocus function as shown below. I also made this function generic so I could call it from any page.
function OnSelectFocus(listObj,divObj,listSize){ var lastScrollPos = divObj.scrollTop; if (divObj.scrollLeft != 0){ divObj.scrollLeft = 0; } if( listObj.options.length > listSize){ listObj.focus(); if(listObj.value==''){ listObj.size = listSize; } else{ divObj.scrollTop = lastScrollPos; } } }
|
|
|
|
 |
|
 |
Tboner, Here is a solution for issues (a) & (b) in a single funtion. The only drawback is the when a user arrows up or down withtheir keyboard, previously selected options remain selected.
First add this to the head section of your web page or preferably in a linked .js file.
function OnSelectFocus2(listObj,divObj){ listObj.size = listObj.length; divObj.focus(); }
Then call this function using the ONFOCUS parameter in each of the select boxes preasent on the page that will utilize horizontal scroll bars.
<DIV ID="scrollBarDiv" STYLE="overflow:auto; width:300px; height:74px"> <SELECT ID="selectBoxA" NAME="selectBoxA" MULTIPLE ONFOCUS="OnSelectFocus2(this,document.getElementById('scrollBarDiv'));"> <OPTION>a<OPTION> </SELECT> </DIV>
Then set the inital focus of your web page to each of the select boxes present on your web page that will utilize horizontal scroll bars.
document.getElementById('selectBoxA').focus
Hope this helps, Pat
|
|
|
|
 |
|
 |
The code passed is nice, however if you like to scroll using keys not just up and downs errors you have problem. I have upgraded your ID and made it also more general
<script> //init selected object and wrapping div. function initSelectScrolls(selectObj) { //Check if items in selectbox is greater than the max size, if (selectObj.options.length >selectObj.size) { var divObj = selectObj.parentNode; divObj.selectboxSize = selectObj.size;//making the size of the selectbox to count of items in selectbox,so that vertival scrollbar won //when a key is pressed on the div it should be passed to the select box //make note that the focus function cause the scrollTop to change to 0, this can we workaround using a timeout function divObj.onkeydown=function(){ setTimeout("syncSelect(document.getElementById('" + divObj.id+ "'),document.getElementById('" + selectObj.id+ "')," + divObj.scrollTop + ")","5"); selectObj.focus();}; //set the selected object events and style to work with the extra div object. selectObj.size=selectObj.options.length; selectObj.style.position = "relative"; selectObj.style.top = "-3px"; selectObj.style.left = "-3px"; selectObj.onkeydown=function(){event.cancelBubble = true;return true;}; selectObj.onchange=function(){syncSelect(divObj,selectObj);event.cancelBubble = true;return true;}; //set the div stlye acording to the selected object size. divObj.style.overflow = "auto"; divObj.style.width = "200px"; divObj.style.height = (divObj.selectboxSize * 18) + "px"; divObj.style.border = "solid 1px #7F9DB9"; //make the div border as if they where the select object borders. } } function syncSelect(divObj,selectObj,realScrollTop) { if (realScrollTop == null) realScrollTop = divObj.scrollTop; var scrollStepHeight = divObj.scrollHeight / selectObj.size; //find out what are the visible options from the select box var minVisibleIdx = Math.round(realScrollTop / scrollStepHeight); var maxVisibleIdx = minVisibleIdx + divObj.selectboxSize; if (selectObj.selectedIndex >= maxVisibleIdx) divObj.scrollTop = (selectObj.selectedIndex - divObj.selectboxSize + 1) * scrollStepHeight; else if (selectObj.selectedIndex < minVisibleIdx) divObj.scrollTop = selectObj.selectedIndex * scrollStepHeight; else divObj.scrollTop = realScrollTop; } </script>
<body önload="initSelectScrolls(document.getElementById('selectWidthScrolls'))"> <select id="selectWidthScrolls" size="9" multiple> <option>This is option 1</option> <option>This is option 2</option> <option>This is option 3</option> <option>This is option 4</option> <option>This is option 5</option> <option>This is option 6</option> <option>This is very very very very very very very very very very very very very very long option</option> <option>This is option 7</option> <option>This is option 8</option> <option>This is option 9</option> <option>This is option 10</option> <option>This is option 11</option> <option>This is option 12</option> <option>This is option 13</option> <option>This is option 14</option> <option>This is option 15</option> = </select>
</body>
-- modified at 6:35 Tuesday 2nd January, 2007
|
|
|
|
 |
|
 |
As the date of the above post may indicate, this seems to be the best cross-browser solution to this horizontal-scroll-on-a-listbox issue imo.
A few considerations: if you're having trouble getting this to display correctly in IE7, try commenting out the following line:
selectObj.style.position = "relative";
I also commented out the following lines, because my divObj styles are handled in the actual DIV element referenced by the parentNode of the selectObj:
selectObj.style.top = "-3px"; selectObj.style.left = "-3px"; divObj.style.overflow = "auto"; divObj.style.width = "200px"; divObj.style.height = (divObj.selectboxSize * 18) + "px"; divObj.style.border = "solid 1px #7F9DB9";
... and it still works in IE7 and FF 1.5.0.12. Haven't tested it in IE6, but with my luck, it probably won't work there :P
|
|
|
|
 |
|
|
 |
|
 |
What about making this a custom control? As I understand, if you have 2 lists on the same page you have to render 2 java scripts (for each list).... this is not very nice .
|
|
|
|
 |
|
 |
Yes, we can also make this as a custom control. It all depends upon your design and architecture of your application.
This sample is meant for developers to understand the listbox's limitations and how to overcome with the same. 
-- modified at 0:33 Wednesday 1st February, 2006
|
|
|
|
 |
|
 |
Hi, nice article, but are you really sure about the headline of the second picture in the preview picture?
morpheus
|
|
|
|
 |
|
 |
Thanks for your feedback. I've updated the picture.
Any comment on this would be appreciable, so that for my next article I make sure I'll implement it
Cheers
|
|
|
|
 |
|
 |
Its clear now.
Well this article is very nice and helpful to me. Keep up the good work buddy......
|
|
|
|
 |