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

Posted on 2014-02-05
Medium Priority
Last Modified: 2014-02-06
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.lblCreation.Text = (DateTime.Now.ToString());
            sticky.FormClosed += new FormClosedEventHandler(sticky_FormClosed);

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;

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

What do I do wrong?

Greetings, Peter Kiers
Question by:peterkiers
  • 3
LVL 45

Expert Comment

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.


Author Comment

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?

LVL 45

Accepted Solution

AndyAinscow earned 2000 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
LVL 45

Expert Comment

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.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Native ability to set a user account password via AD GPO was removed because the passwords can be easily decrypted by any authenticated user in the domain. Microsoft recommends LAPS as a replacement and I have written an article that does something …
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
In the video, one can understand the process of resizing images in single or bulk. Kernel Bulk Image Resizer is an easy to use tool for resizing large number of images. One can add and resize multiple images with this tool in single go. The video sh…

607 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