1

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.

madhead
  • 31,729
  • 16
  • 153
  • 201
Newbie
  • 1,160
  • 2
  • 11
  • 24

2 Answers2

2

you can do this..

 listbox.ScrollIntoView(listbox.Items[listbox.Items.Count - 1]);
loop
  • 9,002
  • 10
  • 40
  • 76
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