在文本框 c# 中输入索引后,我如何选择列表框的项目

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]

当我输入“2”时,他 select listBox 中的第三个名字

你可以这样做:

lstList.SetSelected(index, true);

注意:ListBox 项目是基于零索引的,因此请确保您的输入正确