Shawn

Shawn

  • NA
  • 14
  • 0

Pass info between two forms

Jun 28 2007 1:47 PM
Hello all,

I am coming from a VB .NET background and I am a little confused with how to access another forms properties in C#. Basically I am taking one of the exercises from my VB book and trying to convert to C# to help me learn C#.

Anyhow, here is the task at hand. Form 1 is basically a list view of items that were sold for a particular day. One of the buttons on this form allows the user to open another form to enter the actual items that were sold that day. I have both the interfaces completed, have the second form loading when the user hits the "Enter sales" button on form 1.

However, the next step in my VB book starts the exectution of a do until loop. It accesses the text property of the second form and continuously loops until the text property is empty, meaning the user did not enter another item.

Example: Do Until objAddItemForm.txtItemDescription.Text=""
...process data and add to listview on form 1...
Loop

Ok, so my problem is, how do I access this text field on form 2, to check to see if it is blank, or add its text property to the listview, from form 1?

Thanks for any help,

Shawn

*Edit* - Here is the code I have so far:

Form1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WindowsApplication6

{

public partial class frmTodaysSalesCheck : Form

{

public frmTodaysSalesCheck()

{

InitializeComponent();

}

private void btnEnterSales_Click(object sender, EventArgs e)

{

//Declares objAddItemForm as a new Form

//and opens it in modal form. Modal means

//only the currently activated window is

//accessible for input/action.

Form objAddItemForm = new frmAddItem();

objAddItemForm.ShowDialog();

}

}

}

Form2


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WindowsApplication6

{

public partial class frmAddItem : Form

{

public frmAddItem()

{

InitializeComponent();

}

private void btnOk_Click(object sender, EventArgs e)

{

this.Close();

}

 

}

}


Right now the second form is just closing when the user clicks the Ok button. What I need to do is read the textbox entry on form2 and add it to the listview on form1. Any ideas how to do this?

Thanks again,

Shawn

Answers (3)