How to prevent duplicate items in a listview?

Dear Experts,

I have a listview where the user can insert data via an input-form.
After pressing OK on the inputform the data of the inputform will
be put in a new row in the listview. I have also created a doubleclick
event that when the user doubleclicks on the listview row. The input-
form will appear with the data of the listview row. But its possible
to doubleclick on the listview row twice which opens the input-form
twice also. How can i prevent the user from opening the input-form

Does anyone know the answer, or know an example or show
me the right direction.


Peter Kiers
Who is Participating?
dustockConnect With a Mentor Commented:
Well to prevent duplicate items in your listview just put something like this in.  You didnt specify what language you are using so I provided the example below in C#

            ListViewItem lvi = new ListViewItem();
            var txt = comboBox1.Text;

            if (!listView1.Items.ContainsKey(txt))
                lvi.Text = txt;

                // this is the key that ContainsKey uses. you might want to use the value 
                // of the ComboBox or something else, depending the combobox is freetext 
                // or regarding your scenario.
                lvi.Name = txt;



Open in new window

Are you using form.Show() to open the form on the double click?  If so change it to form.ShowDialog() and then they will not be able to click on the other form until the input form has been closed
Also your title asked about preventing duplicate items in the list view, do you need help on that too?
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

peterkiersAuthor Commented:
Yes, I need help.
peterkiersAuthor Commented:
Oke about the and form.ShowDialog part. It has to be form.Show. So the user can open multiple forms by doubleclicking on the rows of the listview. What I would like to prevent is the user doubleclicking on a row while the form is allready opened. Who can help me? Greetings, Peter Kiers
peterkiersAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.