Solved

How to prevent duplicate items in a listview?

Posted on 2014-01-23
6
743 Views
Last Modified: 2014-01-23
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
twice?

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

Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:dustock
Comment Utility
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
0
 
LVL 9

Expert Comment

by:dustock
Comment Utility
Also your title asked about preventing duplicate items in the list view, do you need help on that too?
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Yes, I need help.
Peter
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Oke about the form.show 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
0
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
Comment Utility
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;

                lvi.SubItems.Add("");
                lvi.SubItems.Add("");
                lvi.SubItems.Add("");
                lvi.SubItems.Add("");

                listView1.Items.Add(lvi);
            }

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Thanks.Peter
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now