Solved

How to prevent duplicate items in a listview?

Posted on 2014-01-23
6
855 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

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

 
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 our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with opening combobox using VB.NET. 3 36
jquery tab header text 1 28
How to force output to ascii 2 37
Consume a webservice via VB in Visual Studio 2015 3 19
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…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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