Solved

How to prevent duplicate items in a listview?

Posted on 2014-01-23
6
792 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

13 Experts available now in Live!

Get 1:1 Help Now