How can you scroll a List Box to the bottom in C#? The items in the ListBox don't have names, which may make it more difficult.
Asked
Active
Viewed 1,064 times
1
2 Answers
2
you can do this..
listbox.ScrollIntoView(listbox.Items[listbox.Items.Count - 1]);

loop
- 9,002
- 10
- 40
- 76
-
It's a ListBox, not a scroll viewer. – Newbie Jul 23 '13 at 12:32
-
i am really sorry for the mistake i have done ..hopw it will solve your problem.. – loop Jul 23 '13 at 12:38
-
2it seems to scroll almost to the end of the ListBox but seems to stop halfway through the last item. – Newbie Jul 23 '13 at 18:04
1
In C#:
yourListBox.SelectedIndex = yourListBox.ItemsSource.Count();
If for some reason you do not have Count
, try this:
public static int Count<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
throw new ArgumentNullException("source");
ICollection collection = source as ICollection;
if (collection != null)
return collection.Count;
int num = 0;
foreach (TSource item in source)
checked { ++num; }
return num;
}

It'sNotALie.
- 22,289
- 12
- 68
- 103
-
This brings up an error, saying there is no definition for .Count andthere is no extension method for .Count – Newbie Jul 23 '13 at 11:11
-
-
I am already using System.Linq; as its a default statement for windows phone projects – Newbie Jul 23 '13 at 13:14
-
@newStackExchangeInstance Can't he use `yourListBox.Items.Count` directly? – anderZubi Jul 23 '13 at 13:41
-