Solved

Pass the content of listview column[1] to a string.

Posted on 2014-02-05
4
215 Views
Last Modified: 2014-02-06
Hi,
I have a listview which the user can enter data through an input-form. When the user double clicks on the row of the listview the input form appears. But when the user double clicks on the same row the input-form appears twice. I am busy to prevent this.

Every input-form has a label with a date showing and it's a unique value stored in the column 1 of the listview when the user closes the input-form. I want to use that unique value to determine if an certain input-form is allready openend. By creating a list of strings. So when the user opens an input-form the date of the label will be added to the list of strings.

private List<string> opened = new List<string><();

        private void bbNewNote_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            StickyNotes sticky = new StickyNotes();
            sticky.gpclCaption.Text = "New Note";
            sticky.rtbContent.Clear();
            sticky.lblCreation.Text = (DateTime.Now.ToString());
            opened.Add(sticky.lblCreation.Text);
            sticky.FormClosed += new FormClosedEventHandler(sticky_FormClosed);
            sticky.Show();
        }

Open in new window


So now I have to write code to determine when the user double clicks on the row of the listview if the input-form allready exists.

        private void lvNotes_DoubleClick(object sender, EventArgs e)
        {
            string selectedId = this.lvNotes.SelectedItems[0].ToString(); <=======
            if (opened.Contains(selectedId)) return;
            OpenSticky(lvNotes.SelectedItems[0]);
        }

Open in new window


At the line that I have marked with an arrow is the line that is not correct.
In that line i have to pass the content of lvNotes.Column[1] to the string
selectedId.

What do I do wrong?

Greetings, Peter Kiers
0
Comment
Question by:peterkiers
  • 3
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39838069
I'd open the input form as a modal window (which disables the form with your your listview until that modal window is closed).

Having said that there should be an Application.OpenForms which contain all open forms in the application - so you can check the contents of that to determine if this input form is already open.

http://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms%28v=vs.110%29.aspx
0
 
LVL 1

Author Comment

by:peterkiers
ID: 39838568
Hi, I need the content of item 1 and put it in a string called selectedID

string selectedId = this.lvNotes.SelectedItems[0].ToString(); <=======

How can i do that?

Peter
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39838631
string selectedId = this.lvNotes.SelectedItems[0].SubItems[0].ToString();
SelectedItems brings a collection of complete rows back, you need to interrogate the sub items to get the column
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39838635
ps.  This is clearly documented in the help files.  You seem to have a habit of asking questions that can easily be solved by yourself just by looking up what the function returns for instance.  In this case there is even example code to do more or less what you wanted.

eg.
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selecteditems%28v=vs.110%29.aspx
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

20 Experts available now in Live!

Get 1:1 Help Now