Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6609683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:44:48+00:00 2026-05-25T19:44:48+00:00

I have a listbox where the Items are Textboxes. I need to set a

  • 0

I have a listbox where the Items are Textboxes. I need to set a key to change the focus to the next textbox and begin the editing of its content.
I have cheated a solution sending Key strokes to achieve what I want, for example:

        ((TextBox)listBox1.Items[0]).KeyDown += (object x, KeyEventArgs y) => { 
            if (y.Key == Key.Enter) { 
                InputSimulator.SimulateKeyDown(VirtualKeyCode.TAB); 
                InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN); 
                InputSimulator.SimulateKeyDown(VirtualKeyCode.TAB); 
            } 
        };

I use the library InputSimulator found here http://inputsimulator.codeplex.com/ for that approach.
I know that this is not the correct way to do it so I’m ask how can i achieve the same using the focus methods. I try with the following code but i get “out of range” error that I don’t understand:

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        for (int i = 0; i < 3; i++)
        {
            listBox1.Items.Add(new TextBox() { 
                TabIndex=i
            });

        }
        for (int i = 0; i < listBox1.Items.Count-1; i++)
        {
            ((TextBox)listBox1.Items[i]).KeyDown += (object x, KeyEventArgs y) => { if (y.Key == Key.Tab) { Keyboard.Focus((TextBox)listBox1.Items[i+1]); } };
        }
        ((TextBox)listBox1.Items[listBox1.Items.Count - 1]).KeyDown += (object x, KeyEventArgs y) => { if (y.Key == Key.Tab) { Keyboard.Focus((TextBox)listBox1.Items[0]); }};

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:44:49+00:00Added an answer on May 25, 2026 at 7:44 pm

    Here is a really short answer for you. In XAML you can use a style to define a common handler for your listboxes…

    <Window x:Class="Interface.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
    
      <Window.Resources>
        <Style TargetType="{x:Type TextBox}">
          <EventSetter Event="KeyDown" Handler="TextBox_KeyDown"/>
          <Setter Property="Width" Value="100"/>
        </Style>
      </Window.Resources>
    
    
      <ListBox Name="lstBoxList">
        <TextBox>ABC</TextBox>
        <TextBox>DEF</TextBox>
        <TextBox>GHI</TextBox>
      </ListBox>
    
    </Window>
    

    So you can see all of the text boxes in the list. The actual handler code will look like this…

    private void TextBox_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.Key == Key.Enter)
      {
        // Locate current item.
        int current = lstBoxList.Items.IndexOf(sender);
    
        // Find the next item, or give up if we are at the end.
        int next = current + 1;
        if (next > lstBoxList.Items.Count - 1) { return; }
    
        // Focus the item.
        (lstBoxList.Items[next] as TextBox).Focus();
      }
    }
    

    So the basic concept is that you will locate the current text box in the list. Then you will find the next one somehow (tags, names, etc.) and focus it explicitly. Of course you will have to tweak depending on your exact need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox that each of its items has a button, I set
I have a listbox being populated from textbox entry. { textBox2.Text.Replace(\r\n, \r); listBox1.Items.Add(textBox2.Text); }
I have a ListBox showing items using the following DataTemplate: <DataTemplate x:Key=PersonTemplate DataType={x:Type DAL:ResultItem}
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>
I have a ListBox which displays items of variable height. I want to show
I have a ListBox displaying some items, and in certain modes I stamp a
I have a ListBox with way too many items in it and the UI
I have a ListBox containing a group of 'Expander' items, and what I would
I have a ListBox bound to a list of Items (for arguement, lets say
I have a listbox that displays Shipment Items (custom class) that are formatted using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.