Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a ListBox display all data from the database. Can do a multiple selections as well but only one selected item possible to edit in a same time.

I tried the following code but working only with the else branch but I want put my full code into the if branch.

What I missed? How to revers?

What I have tried:

if (listBox.SelectedItems.Count != 1)
Do modificate selected item.
MessageBox.Show("Only one item can be edit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Updated 21-Nov-22 5:53am

1 solution

Your code is almost right, just change the first line:
if (listBox.SelectedItems.Count == 1)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900