Pass text from a textbox on a dialogform to the listview on the main form.


I have a main form called MainForm and a dialog form called StickyNotes.

In the close or closing event of the form StickyNotes I want to put this line:

lvNotes.SelectedItems[0].Text = frmNote.textBox1.Text;

But the lvNotes is a listview that resides on the mainform

Who knows the solution?

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Don't try to "push" from StickyNotes to MainForm.

Instead, "pull" from MainForm to StickyNotes.

Since you are displaying StickyNotes as a dialog, MainForm will stop execution until StickyNotes is closed.  Furthermore, MainForm will already have a reference to StickyNotes since that is where it was created.

First you need to change the Modifiers() property of textBox1 on StickyNotes to public.

Afterwards, it would look something like this in MainForm:
public partial class MainForm : Form

        private void btnStickyNotes_Click(object sender, EventArgs e)
            StickyNotes sn = new StickyNotes();
            if (sn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                this.lvNotes.SelectedItems[0].Text = sn.textBox1.Text;


Open in new window

peterkiersAuthor Commented:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.