Writing a ListBox value to another Form

Posted on 2006-06-04
Medium Priority
Last Modified: 2010-04-16
I'am trying to write the current selected value in a listBox to another form. Here is the code so far:

public class MainForm : System.Windows.Forms.Form
            private System.Windows.Forms.ListBox mainList;
            private UpdateStudent _updateForm;


private void btnUpdate_Click(object sender, System.EventArgs e)
      this._updateForm = new UpdateStudent();

      this._updateForm.stuName.Text = mainList.SelectedItem.ToString();      

It is trying to set the stuName text in the updateform to the currently selected Item in the mainList listbox. However, when I access the _updateForm, stuName is empty. Why is it not being populated with the text of the currently selected line in the listbox? Also, it compiles fine.

Question by:igor92128
1 Comment
LVL 96

Accepted Solution

Bob Learned earned 1000 total points
ID: 16829524
Reverse these 2 lines:

     this._updateForm.stuName.Text = mainList.SelectedItem.ToString();    


You were showing the form before you set the text.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 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