Solved

Add a row to a listview from another form.

Posted on 2011-09-17
6
403 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
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.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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