Guido Visser
Guido Visser

Reputation: 2299

C# Edit last item in listbox without having it selected

I am trying to edit the last item in a listbox without having it selected. Because I can't select items in the list (this is my default for my application). It's a Windows Form Application.

Normally I would do something like: listBox1.SelectedIndex = listBox1.Items[listBox1.SelectedIndex] + " -> This string is added" but because I can't select anything, this won't work.

Can someone help me out here?

Upvotes: 3

Views: 1144

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236208

You can get last item from Items collection by index:

listBox1.Items[listBox1.Items.Count - 1] + " -> This string is added";

Upvotes: 1

Related Questions