Writing a ListBox value to another Form

Posted on 2006-06-04
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

    Reverse these 2 lines:

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


    You were showing the form before you set the text.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    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.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    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…

    758 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