Solved

Add a row to a listview from another form.

Posted on 2011-09-17
6
410 Views
Last Modified: 2013-12-17
Dear Experts,

I have a main form named mainForm with a listview on it, and a toolbar-button
for calling a second form named StickyNotes. On the StickyNotes I have a txtbox
and a close button.

What I would like is when a user clicks on the toolbar-button to open form StickyNotes
and put some text into the textbox and the presses the close-button. A new row must
be inserted into the listview that resides on the mainForm with the text of the textbox
into the column lvcCaption.

As you can see I have done it myself only I don't how to get to the listview on the mainForm
from the StickyNotes form!

How can I do that?

Who knows the answer and is willing to help me?

Greetings, Peter Kiers
private void StickyNotes_Load(object sender, EventArgs e)
        {
            txtCaption.Text = "";
            rtbContent.Clear();
            lblCreation.Text = (DateTime.Now.ToString());
        }

        private void StickyNotes_FormClosed(object sender, FormClosedEventArgs e)
        {
            ListViewItem myItem = new ListViewItem(txtCaption.Text, 0);
            myItem = lvNotes.Items.Add(myItem);  <=============================
            myItem.SubItems.Add(rtbContent.Text);
            myItem.SubItems.Add(lblCreation.Text);
        }

Open in new window

0
Comment
Question by:peterkiers
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:effes
ID: 36553647
Hi Peter,

you could expose the values you need as public properties of the StickyNotes class. In your StickyNotes_FormClosed method assign the proper values to these properties and once you are back inside your mainForm you can read the values of the properties to create a new entry in your ListView.

Hope that helps,
Frank
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36553652
Could you PLEASE help me? Give me an example or something?

Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36553689
I had this code before, for using a single form.
But now I want to make use of multiple forms.

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

Open in new window

0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 6

Expert Comment

by:effes
ID: 36553724
What do mean when you say "multiple forms"? Do you want to display more than one StickyNotes form at once?
What's wrong with the code in your last post?
0
 
LVL 2

Accepted Solution

by:
ASP8MBM earned 500 total points
ID: 36553734
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36553857
Thank you for all the info.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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