locked
move cursor in listbox items RRS feed

  • Question

  • move cursor in listbox items

    i make silverlight application and i have list box..in this list box i add textbox item template..

    so now i have a list of text boxes...

    Now i want when i press enter in textbox to set the cursor into next textbox in the list..

    Friday, September 4, 2009 5:35 AM

Answers

  • You can use the VisualTreeHelper to iterate all the child controls of your list box.

    Would just be a matter of working out the next sibling of the current textbox and setting focus to it.

    Wednesday, September 9, 2009 4:08 AM

All replies

  • You will need to capture the KeyDown event and manually move focus to the next textbox.

    Friday, September 4, 2009 8:45 AM
  •  i will show u wht i try to do.

    i have listbox of itemtemplate of textboxes only

     <ListBox Name="lstfood" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBox Width="100" Text="{Binding name}" KeyDown="TextBox_KeyDown" Name="txt1"></TextBox>
              
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

    and i make sample calss contain prop "name" and bind a list to this listbox

    and as u see i capture keydown as u said

    private void TextBox_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Down)
                {

    //i want here to set focus to the next textbox in this listbox

            }

    Wednesday, September 9, 2009 3:02 AM
  • You can use the VisualTreeHelper to iterate all the child controls of your list box.

    Would just be a matter of working out the next sibling of the current textbox and setting focus to it.

    Wednesday, September 9, 2009 4:08 AM