all groups > dotnet windows forms databinding > december 2004 >
You're in the

dotnet windows forms databinding

group:

Transferring data between controls on form2 and datagrid on form1


Transferring data between controls on form2 and datagrid on form1 Mark Chimes
12/31/2004 1:12:34 PM
dotnet windows forms databinding: Hi all,

I have an MDI app with a couple of forms.

Form 1 contains (amongst other things) a DataGrid and a button on a Pane.
When the button is clicked a second form opens. When the combobox and text
controls on this second form have been suitably filled and saved, I need the
data from these controls to be added to a row in the DataGrid on the first
form.

How do I do this?

Cheers,
Mark

Re: Transferring data between controls on form2 and datagrid on form1 Stuart Celarier
1/7/2005 8:01:46 AM
[quoted text, click to view]

One way is to expose the data as (read only) properties of the form, such as

using System.Windows.Forms;

public class Form2 : Form
{
private ComboBox domainObjectComboBox;
public object DomainObject
{
get { return domainObjectComboBox.SelectedItem; }
}

private TextBox descriptionTextBox;
public string Description
{
get { return descriptionTextBox.Text; }
}

// ...
}

And provide Form1 a mechanism for obtaining a reference to Form2.

Cheers,
Stuart Celarier | Fern Creek | www.ferncrk.com
AddThis Social Bookmark Button