Jacob Schoen
Jacob Schoen

Reputation: 14212

Control like ListBox but has buttons to move up and down the list

I am looking for a control that looks like a TextBox with an up and down button on the right hand side. As you click the buttons it should change the index of the selected item in the list. It should only show one item at a time. Hopefully this picture will better articulate what I am looking for:

TextBox with up and down button to move through the list of items

I was hoping there was a way to style a ListBox or ComboBox to pull this off, but that does not seem possible. I considered using a slider, but my list of values may or may not have gaps, (i.e. it could be 150, 151,153,160,...).

I can get close with a ListBox by setting the height, but it does not change the SelectedIndex as you scroll:

<ListBox Height="23" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center">
  <ListBoxItem>1</ListBoxItem>
  <ListBoxItem>2</ListBoxItem>
  <ListBoxItem>3</ListBoxItem>
  <ListBoxItem>4</ListBoxItem>
  <ListBoxItem>5</ListBoxItem>
</ListBox>

So is there away to hook into the scroll buttons so that when the buttons are clicked I can adjust the index appropriately? A secondary question would be, is there away to set the number of items to display in a `ListBox' before the scroll bars are added, instead of setting the height?

Upvotes: 0

Views: 446

Answers (2)

arifnpm
arifnpm

Reputation: 417

Maybe you can use NumericUpDown control instead. and change the list index on ValueChanged event.

Upvotes: 1

Arclight
Arclight

Reputation: 483

If you're using WinForms, there's a control for this purpose:

http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.aspx

For WPF, you may consider this one:

http://wpftoolkit.codeplex.com/wikipage?title=NumericUpDown&referringTitle=Home

Upvotes: 1

Related Questions