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

x
?
Solved

Add a row to a listview from another form.

Posted on 2011-09-17
6
Medium Priority
?
431 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 2000 total points
ID: 36553734
0
 
LVL 1

Author Comment

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

Peter
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

963 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