Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Form show instead of showmodal.

Posted on 2012-04-09
4
Medium Priority
?
264 Views
Last Modified: 2012-04-09
Hi,

I have a mainform called mainForm with a listview on it called lvNotes.
And a second form called StickyNotes. With this code below I can call
for the form StickyNotes, put some text on it and after closing the
StickyNotes a row will be inserted in to the listview lvNotes on the mainForm.

This all works super. But now I want to show multiple stickynotes when I press
on the button.

How can I do that? What do I have to change?

        //*------------------------------------------------------------*//
        private void tbNewNote_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmNote.lblTitle.Text = "";
            frmNote.rtbContent.Clear();
            frmNote.lblCreation.Text = (DateTime.Now.ToString());
            if (frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ListViewItem myItem = new ListViewItem(frmNote.lblTitle.Text, 0);
                myItem = lvNotes.Items.Add(myItem);
                myItem.SubItems.Add(frmNote.rtbContent.Text);
                myItem.SubItems.Add(frmNote.lblCreation.Text);
                myItem.Selected = true;
            }
        }
        //*------------------------------------------------------------*//
        private void lvNotes_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            frmNote.lblTitle.Text = lvNotes.SelectedItems[0].Text;
            frmNote.rtbContent.Text = lvNotes.SelectedItems[0].SubItems[1].Text;
            frmNote.lblCreation.Text = lvNotes.SelectedItems[0].SubItems[2].Text;
            if (frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                lvNotes.SelectedItems[0].Text = frmNote.lblTitle.Text;
                lvNotes.SelectedItems[0].SubItems[1].Text = frmNote.rtbContent.Text;
                lvNotes.SelectedItems[0].SubItems[2].Text = frmNote.lblCreation.Text;
            }
        }
        //*------------------------------------------------------------*//

Open in new window


Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
  • 2
4 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37822675
private readonly List<Form> _forms = new List<Form>()
                                        {
                                            new Form2(),
                                            new Form2(),
                                            new Form2()
                                        };

_forms.ForEach(f=>f.Show());

Open in new window


This will show multiple instances of Form2
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37822839
Hey BuggyCoder I don't know exactly what to do with your solution.

It have to be like this:

On my mainform I have a button, by pressing on the button everytime
a form appears. On the form is a textbox. So if the form closes
the text of the textbox on the form will be written to the listview on the
main form.

How can I do that?

Peter
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37823231
Try something 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;
        }

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
ID: 37823492
Super.

Idle_mind gets 500 points...

Peter
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 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