Solved

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

Posted on 2011-09-05
2
289 Views
Last Modified: 2013-12-17
Hi,

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?

Peter
0
Comment
Question by:peterkiers
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 36485842
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

0
 
LVL 1

Author Comment

by:peterkiers
ID: 36485867
Thanks.

Peter
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 45
C# Update Status Bar.... 1 24
String manipulation 15 49
Events in static methods 3 31
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

11 Experts available now in Live!

Get 1:1 Help Now