Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Double click on listview row opens the same forms more than ones. Part2

Hi,

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
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Wasn't it solved with the previous question ? What did you already try and what is the issue you're still having ?


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
        }
Avatar of Peter Kiers

ASKER

Hi Dhaest,

I have tried your altered code but still have the same problem.
I didn't tried the first possibility. Because I don't know how to
implement that code.

As you can see in the example.jpg I have still the same problem.
When I click on the icon of the listview more than ones the form
also appear more than ones.

Peter
Example.jpg
SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

I want my StickyNotes behave like Microsoft Outlook does. So it is possible. When a user press the new button, the StickyNotes form apears (and for every newly created StickyNotes form a new row will be created in the listview. So, if the user pressed the new button the first StickyNotes form appears, if the user presses the new button again a second StickyNotes form appears, but the first StickyNotes form will be minimalized automaticly.
etc...And the user can display multiple forms by doubleclick on the StickyNotes forms that are minimized. This works super. And this behaviour is what Microsoft Outlook does too.

But when you doubleclick on an icon (row) of the listview in Outlook. And the StickyNotes form is allready minimized. Outlook displays the minimized StickyNotes form. In my case
the programm created a second StickyNotes form !!!

I have test the code above from Dhaest.its not 100% but I think where on the right track.
It doesn't display the minimized form as normal, and when I put text into the textbox
of the stickynotes form the text isn't saved anymore. Can I have the code translated because I have no idea what it does!

Peter Kiers
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Idle_mind this is the right solution. And also thanks Dhaest for responding.

Peter