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

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

How to scroll WPF Listbox to the end?

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :WPF
How can I scroll WPF ListBox to the end programmatically? Selecting of last item doesn't work as in Windows Forms.

View Complete Post

More Related Resource Links

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.


How can I make the listbox scroll to the selected item

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?    

System.Windows.Forms.ListBox scroll-to-top on focus - how can I prevent this behavior?




I've been trying to find a solution online for the last couple days and I'm surprised at how little there is on this topic -- namely, I'm trying to prevent the default behavior of ListBoxes scrolling to the top whenever they regain focus.


I've created a toolbar-like control that is docked on the left-hand side of my screen.  This vertical toolbar is comprised of several ListBoxes, and each ListBox is collapsible (much like the Visual Studio designer toolbar).  The problem is, if I click on an item on a ListBox that is partially off the top of the screen, the entire toolbar scrolls so that the first item in that particular ListBox is at the top, so your mouse is no longer over the item you originally wished to select.


I'm trying to figure out a way to prevent this behavior.  Any suggestions?



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

ListBox tricky to set in a DataGrid/GridView

Listboxes are very tricky to set selected items in grid - there is no real nice way to do it. It would have been great if Microsoft included a property that accepts an array or comma separated values - or anything! But they only allow each item in the list to be selected individually. The way to do this in a grid is a bit messy, but it is fairly simple to implement. When a row is created (as per the event), select the items of the listbox as per the datagrid source data:

Working with DropDownList and ListBox Controls in ASP.NET

"In my application i am using dropdownlist to display all categories from a table. When the user clicks this control I display all records in that category. Category table also contains column called color.

I wanted display some categories in dropdown list different color and others in different color using ASP.NET."-Anonymous

Persist data in a dynamically populated ListBox in a user control


Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)










My Click Function

Protected Void Button1_Click(object sender, EventArgs e)


       string strValue = listBox.SelectedValue



I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

ActiveX and Visual Basic: Enhance the Display of Long Text Strings in a Combobox or Listbox


The combobox and listbox controls in Visual Basic have no built-in support for displaying text strings that are too long to fit in the visible area of either control. This article describes several techniques to improve the readability of long strings in each control. The first technique uses tooltips to display a combobox or listbox item. The other techniques, which use various Windows APIs, include adding a horizontal scrollbar for a listbox and determining the necessary width of the longest string given the font attributes of the text. The required steps are described for both comboboxes and listboxes.

John Calvert

MSDN Magazine December 2000

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? 

Filter a listbox with textbox


So i currently filter the listbox with some javascript i have found.
What it does is going to the item i type on the textbox.
It will not filter the listbox so it will contain the specific matches.
I was reading for autocomplete but i don't seem to find this 2 way usage.
I was also reading this article:
But i'm completely lost on how i can implement it.
Any ideas?

How to reference a listbox from a procedure


I have a listbox that gets loaded from a couple of different places on my web form.

I would like to put the code to load the listbox in one place, rather than have two copies of it.

The problem is, I can't figure out how to reference the listbox control successfully from within a procedure.

Would anyone know how to do this?

My code looks like this:

private static bool LoadSubscriptionListBox(System.Web.UI.Page Page)
        bool bReturn = false;

        // Clear the listbox

        // Load the listbox



jQuery modified ListBox not posting back modified values


Hi everyone,

I have an ASP.Net ListBox that I'm trying to populate via jQuery, using the following snippet:

        $("#MyList_btnAddAll").click(function(e) {
        $('#MyList_lstAll option').appendTo('#MyList_lstSelected');

The code has two ListBoxes in fact, one a "source" and the other a "destination".  As you can tell above the ListBoxes are MyList_lstAll and MyList_lstSelected.  These are rendered in the browser as <select> elements, as you'd expect.

The jQuery is working great, the items are moving from one ListBox to the other, the DOM is updated but when I submit this form (not using jQuery), the ListBoxes don't reflect this change on postback. 

I realize my modifications via jQuery aren't available in ViewState but I thought since the DOM was updated these changes would be part of the postback data?  But in the codebehind after postback the ListBox contents haven't changed.  Does anyone know what might be going on and what I can do about it?  Many thanks.

How I disable vertical scroll bar of report viewer control on Web Form.


I'm displaying .rdlc report file using Report viewer control on Webform. If  I Fix height of viewer control and data is not same as to size of viewer control then it display one scrollbar on viewer control and second vertical scroll bar is coming on webpage.

 I want to off viewer vertical scrollbar or in simple word's I don't want to display two scroll bar with my report. Please guide me or send me reference if any.


How to create a dynamically populated items in a listbox and use it as a navigation?

Hello, I am trying to create navigation inside a listbox menu. I load data from xml to populate a list. Each item in the list box should be a link or button. Then, I create a frame to load xaml pages in it. I tested to load pages employing button control, outside listbox with on click event and it worked well. However, I cannot make it work with list box items. I am hoping to get help from you. Any sample or ideas are highly appreciated. Below is the code:  XML: <?xml version="1.0" encoding="utf-8"?> <Pages> <page id="page01"> <name>Page 01</name> </page> <page id="page02"> <name>Page 02</name> </page> </Pages> C# to initiate a click o n listbox item and get the path to page: private void SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem); string itemName = lbi.Content.ToString(); if ( Nav_ListBox.SelectedItem.Equals("Page01" ) ) { ContentFrame.Source = new Uri("Pages/Page01.xaml", UriKind.RelativeOrAbsolute); } } XAML:  <ListBox x:Name="Nav_ListBox" Margin="0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Background="#FFF2F2F2" ItemTemplate="{DynamicReso

Page to page navigation from listbox menu?

I am wondering if anyone can share with good sample on how to create menu populated in a listbox from xml and have page to page navigation between xaml pages. I need to have a unique Uri link associated with each item in the listbox. Any advice is highly appreciated. Thank you in advance,

Data binding a listbox

I'm using VS 2010 and writing a WPF application.  I have a listbox on a form that I want bound to an access database field.  In the code behind I create the usual oledb connection, command and adapter and run a query.  In debug I can see the dataset has 143 items from the database, a single column called "path".  Here's the relevant code:  oleCon.Open(); adpt.SelectCommand = oleComd; adpt.Fill(dtst,"MyTable"); MusicList.DataContext = dtst; MusicList is the listbox.  There's 143 items in the dataset.  When the form loads the listbox is empty.  Here's the xaml for the listbox: <ListBox Grid.Row="1" Height="477" HorizontalAlignment="Left" Margin="7,6,0,0" Name="MusicList" VerticalAlignment="Top" Width="310" Grid.RowSpan="2" Background="#002400" ItemsSource="{Binding Path=path, Mode=OneTime}" DataContext="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding Path=path}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> At least I know the data is present but why isn't it binding to the listbox? Thanks!  
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