Solved

Add a row to a listview from another form.

Posted on 2011-09-17
6
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 our DevOps Teams Maximize Uptime

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

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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:…
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!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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