gizgok
gizgok

Reputation: 7649

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.

Upvotes: 1

Views: 4566

Answers (3)

Ang
Ang

Reputation: 35

Or:

ListBox_Admin.SelectedValue = "";

Upvotes: -2

tchrikch
tchrikch

Reputation: 2468

Try this

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

Upvotes: 0

kprobst
kprobst

Reputation: 16651

Something like this?

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

Upvotes: 3

Related Questions