.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How can I make the listbox scroll to the selected item

Posted By:      Posted Date: September 09, 2010    Points: 0   Category :ASP.Net
Hi All, I have a textbox that searches the listbox below it and selects the text that I types in the textbox. Now although the item is selected in the listbox I have to scroll to the end to see if the item is selected ornot IS there a way that I can make the list box scroll to the selected item?    

View Complete Post

More Related Resource Links

Make an item as Non Selectable in WPF - ListBox

Hi All,How to make a list item as non selectable in WPF Listbox?I have a listbox with five items (Normal single column text).(Doesn't have checkbox)My requirement is the user should not  to make Select/Focus the 1st and 4th item in ListBox. (Because that is header of following items)Any suggession/solution?ByRamesh.p Yes! We can!!

auto-scrolling to the selected item in a listbox



I have a listbox which is populated with items at Page_Load and has 5 items visible at a time.  Then there is a textbox where the user types some characters. On keyup event of the textbox  my code searches the listbox for the entered value and selects the item closest to the entered value. However the selected item appears as the 5th item in the listbox. I want it to be the 1st item displayed.

Any ideas ??


The selected item in my listbox is always the previous item


It's easier if you see the code but I'll give you the specific problem. My listbox is set to contain a grid format and each listboxitem has a ListBoxItem.PreviewMouseLeftButtonDown event. The problem is, the selected item is always set to the previous item.

Here is what happens in steps:


1. My image loads up

2. I click a button to generate a grid overlay of 32x32 cells over the image, each a listboxitem in a cell of that overlay

3. I click on a cell 

4. OnSelected method fires (each listboxitem is tied to this handler through the ListBoxItem.PreviewMouseLeftButtonDown event)

5. The SelectedItem is null when I click on cell (0,0)

6. If I click on cell (0,1), the ListBoxItem.PreviewMouseLeftButtonDown event fires but now the SelectedItem is set to the object in the previous cell (0,0) instead of (0,1). Then, clicking on (0,0) will show the SelectedItem as being (0,1) and so on.

7. Repeat for any other cell.



<DockPanel Name="dockTest"

trouble displaying data from selected item in listbox


I have a asp.net web form in which I display registered customers in a listbox. In the listbox I can choose one customer, and click a "Show data"-button. That should display all registered data about the chosen customer in textboxes next to the listbox. This doesn't work and I haven't been able to find where the error lies. Instead of displaiyng the data in the textboxes the error message in:  LabelNoCustomerChosen is displayed. Could it be that the program doesn't find the customer ID? The string that is displayed in the listbox looks like this:

ID Lastname, Firstname

Here's my "Show data"-button click:

protected void ButtonCustData_Click(object sender, EventArgs e)

        string Firstname;
        string Lastname;
        string Street;
        string No;
        int Zip;
        string City;
        string Email;
        string Phone;

        if (ListBoxSearchCust.SelectedItem == null)
            LabelNoCustomerChosen.Visible = tru

C# listBox ScrollIntoView doesn't scroll to Selected Index


I have a WPF window that includes several ComboBoxes and ListBoxes. I have a button that is meant to reset the selected item in all the ComboBox and ListBox to the top item. This is designed to allow the User to "reset" their search parameters.

The programmatic selection of Index 0 works for all the boxes but the ListBox is presenting a problem. When I programmatically select index 0 in the ListBox it doesn't scroll to the selected Item. Because of this the user isn't immediately aware that the selection has been moved to the top item.

Here is the code I'm using:

private void button3_Click(object se

How to keep the hover for Parent menu and set the selected menu item css for child menu item?



I'm using cssfriendly control adapter for menu. My asp.net menu control's datasource is a sitemap file I'm using which contains all the urls.

I have the following questions:

  1. Is there a way to keep the parent menu item hovered while hovering over the respective child menu items?
  2. Is there a way to keep the child menu item selected? I am able to set the css for the parent menu, however I was wondering if the same is possible with the child items.

Please help! Smile


Moneka Smile

ASP.NET 4.0 Menu Top Level selected item style


I want to apply a css class to the level 1 menu item (parent) when it or any or it's children are selected.

I've looked at MSDN documentation and any number of examples and walkthroughs but I haven't come up with a way of managing this. I was thinking something like this might work but the style is not being applied to the parent. To further complicate matters, if I try to apply a css style to StaticSelectedStyle it doesn't pick it up at all.

Menu Markup:

<StaticSelectedStyle  Font-Bold="True" ForeColor="#3333CC" />

Code Behind:

        protected void MenuItemClick_NavMenu(Object sender, MenuEventArgs e)


            MenuItem parentItem = e.Item.Parent;

            if (parentItem != null)


                parentItem.Selected = true;



setting scroll position for a ListBox


I have a ListBox control showing 10 rows.  I have 30 rows total in the listbox.  How do I programmatically adjust the scroll to show the last ten rows?

Some sources have suggested that I set the SelectedItem.  But I am already making selections (myListBox.Items[28].Selected = true, myListBox.Items[29].Selected = true, etc); the listbox scroll is positioned on Item[0] not the first selected item.  I have also tried setting myListBox.SelectedItem in addition to the multiple selection just mentioned but that does not have any affect either.


Dynamically Populate a DVWP depending on selected item



I am wanting to create a dashboard page with several data view web parts which dynamically populate depending on what item is selected in a separate web part (drop down form or just a list of links).  Can someone please point me to a tutorial or documentation on how to pass data between web parts or to a DVWP?  I have searched for a few hours and not been able to find anything useful.



How to make browser scroll to the bottom of page


Hi All,

  How to use asp.net C# to scroll to the bottom on page on post back or programmatically decision? 

Javascript code to copy selected dropdown item to clipboard

Does anyone know how I can do this to get the text onto the clipboard?  <input id="Copy" type="button" value="Copy Url" runat="server" onclick="copy();" style="vertical-align: top;" visible="false"/><script type="text/javascript"> function copy() { var sel = document.getElementById("DropDownList1"); var text = sel.options[sel.selectedIndex].value; ??? } </script> </body>  

Button to copy selected item in dropdown to textbox

Hi, I found this bit of code which I tried and it isn't working. I just want to place a button next to a dropdown, and when clicked, the selected item in the dropdown will put into another textbox. <head><title>Untitled</title></head><body><script type="text/javascript">function copy() {var sel = document.getElementById("names");var text = sel.options.value;var out = document.getElementById("output");out.value += text+"\n";}</script> <select id="names"><option>Product One</option><option>Product Two</option><option>Product Three</option><option>Product Four</option></select><input type="button" onclick="copy()" value="Copy"><textarea id="output"></textarea> </body></html>   I saved this as a file and opened it in IE to test and nothing went into the textarea. Also i tried it in Firefox and the textarea said undefined each time I click the button. Can someone help to get this working?

radiobutton list item make visible true or false in javascript

in my project i have used one radiobuttonlist according different user login , i want to make one of radiobuttonlist item visible true or false..   please help me to solve this issue.   thanks in advance.  

VS2008 and C#: How to create a short cut for a selected item in a ListView/TreeView ?

How to create a short cut for a selected item from a ListView/TreeView ? Is it possible to provide a smaple code ? Thanks,

how to in Insert database NULL if drop down list item is not selected ?

hi,   on my aspx I have the below DDL   <asp:DropDownList ID="ColorDDL" runat="server" DataSourceID="ColorObj"                                                 DataTextField="Size" DataValueField="BustId" Width="150px"                                                 AppendDataBoundItems="True">                                                    <asp:ListItem Value="-1">(Optional)</asp:ListItem>                             &n

Get bounding rectangle of a listbox item

Hi everyone, I can add a String or a ListBoxItem into Listbox. When item of Listbox is a ListBoxItem , I can get ListBoxItem 's rectangle by calling "ListBoxItem.PointToScreen(point)". But I can not get rectangle of an item if this item is a String . Any help would be appreciated!

Trap Selected Index change event of listbox using Javascript.

Hi All, This is reagarding listbox selection. I have a list box with multi select option. I want to trap the selected index change event of Listbox through javascript. Item of list box can be selected using Click of mouse and also the keyboard up down key with shift. I tried onclick event to bind the javascript function. It works fine if I select by mouse, but it doesen't work for up/down key of keyboard. Thanks, Naveen
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend