Solved

How to prevent duplicate items in a listview?

Posted on 2014-01-23
6
824 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
ID: 39803273
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
ID: 39803281
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
ID: 39804240
Yes, I need help.
Peter
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 1

Author Comment

by:peterkiers
ID: 39804286
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
ID: 39804393
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
ID: 39805009
Thanks.Peter
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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