Link to home
Start Free TrialLog in
Avatar of igor92128
igor92128

asked on

Writing a ListBox value to another Form

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();
            _updateForm.ShowDialog();

      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.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial