Solved

Doubleclick on listview row opens same forms more than ones.

Posted on 2012-04-10
2
435 Views
Last Modified: 2012-04-10
Hi,

I am programming in C# and I use VS2010.

I have a mainform with a listview called lvNotes on it. And a button for
displaying another form called StickyNotes. On the StickyNotes there
is a textbox where the user can put some text when he/she closes the
form the text of the textbox will be displayed in a new row in the listview.

The code looks like this:

        private void tbNewNote_ItemClick(object sender, ItemClickEventArgs e)
        {
            StickyNotes sticky = new StickyNotes();
            sticky.lblTitle.Text = "";
            sticky.rtbContent.Clear();
            sticky.lblCreation.Text = (DateTime.Now.ToString());
            sticky.FormClosed += new FormClosedEventHandler(sticky_FormClosed);
            sticky.Show();
        }
        //*------------------------------------------------------------*//
        void sticky_FormClosed(object sender, FormClosedEventArgs e)
        {
            StickyNotes sticky = (StickyNotes)sender;
            ListViewItem myItem = new ListViewItem(sticky.lblTitle.Text, 0);
            myItem = lvNotes.Items.Add(myItem);
            myItem.SubItems.Add(sticky.rtbContent.Text);
            myItem.SubItems.Add(sticky.lblCreation.Text);
            myItem.Selected = true;
        }
        //*------------------------------------------------------------*//
        private void lvNotes_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            StickyNotes sticky = new StickyNotes();
            sticky.lblTitle.Text = lvNotes.SelectedItems[0].Text;
            sticky.rtbContent.Text = lvNotes.SelectedItems[0].SubItems[1].Text;
            sticky.lblCreation.Text = lvNotes.SelectedItems[0].SubItems[2].Text;
            sticky.Show();
        }

Open in new window


But when the user doubleclicks on the row of the listview the stickynotes form
appears again. But when the user clicks again on the same row the stickynotes
form appears twice. So I have to tell in the doubleclick-event that If the user
doubleclicks on the listview row and the Sticky Notes form of that row the user
is clicking on is still open/active then ignore.

How can I do that?

Peter
0
Comment
Question by:peterkiers
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 37826963
I see 2 possibilities:
1. Check if the form is already open:
http://hashfactor.wordpress.com/2009/01/28/c-check-if-a-form-is-already-opened/

2. Move a little bit in the code


        public StickyNotes sticky ;
        private void tbNewNote_ItemClick(object sender, ItemClickEventArgs e)
        {
            sticky = new StickyNotes();
            sticky.lblTitle.Text = "";
            sticky.rtbContent.Clear();
            sticky.lblCreation.Text = (DateTime.Now.ToString());
            sticky.FormClosed += new FormClosedEventHandler(sticky_FormClosed);
            sticky.Show();
        }
        //*------------------------------------------------------------*//
        void sticky_FormClosed(object sender, FormClosedEventArgs e)
        {
            sticky = (StickyNotes)sender;
            ListViewItem myItem = new ListViewItem(sticky.lblTitle.Text, 0);
            myItem = lvNotes.Items.Add(myItem);
            myItem.SubItems.Add(sticky.rtbContent.Text);
            myItem.SubItems.Add(sticky.lblCreation.Text);
            myItem.Selected = true;
           sticky  = null;
        }
        //*------------------------------------------------------------*//
        private void lvNotes_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            sticky = new StickyNotes();
            sticky.lblTitle.Text = lvNotes.SelectedItems[0].Text;
            sticky.rtbContent.Text = lvNotes.SelectedItems[0].SubItems[1].Text;
            sticky.lblCreation.Text = lvNotes.SelectedItems[0].SubItems[2].Text;
            sticky.Show
        }
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37827112
Thanks.

Peter
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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 regular expression to search string 6 29
location of a form 2 24
JSON Deserialize issue 6 26
Need syntax help building hyperlink 2 20
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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:…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

792 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