简体   繁体   中英

How to insert a new item in a listbox and then setfocus on the listbox new item on a button click event in C#

I have a listbox which populated from using a datatable. I have a Add button in my page. On clicking the add button I want to insert a blank row in the listbox. This can be done easily by

ListBox_Admin.Items.Add("");

after this is done I want to select this item as in setfocus on this item.How do I do this.

Something like this?

listBox1.Items.Add("");
listBox1.SelectedIndex = listBox1.Items.Count - 1;

Try this

ListBox_Admin.Items.Add(item);
ListBox_Admin.SeletedItem = item;

要么:

ListBox_Admin.SelectedValue = "";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM