Solved

Add a row to a listview from another form.

Posted on 2011-09-17
6
388 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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:…
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!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now