Search code examples
c#indexingtextboxlistboxselectedindex

how i can selected item of listBox after enter the index in textBox c#


        int index;
        index = int.Parse(txtIndex.Text);
        lstList.SelectedIndex = index;  [enter image description here][1]

when i enter "2" he select the third name in listBox


Solution

  • You can do this:

    lstList.SetSelected(index, true);
    

    NOTE: ListBox items are zero index based so be sure that you have the correct input