views:

43

answers:

3

For example if I have a Name object

public class Name
{
    public string First { get; set; }
    public string Middle { get; set; }
    public string Last { get; set; }
}

and I have a form with 3 textboxes on it, named txtFirstName, txtMiddleName, txtLastName

I want some way to automatically bind the domain object to these text boxes.

I'm very used to working with asp.net-mvc but I'm trying to transfer this knowledge to winforms 0_0

A: 

I'm not quite sure if this is what you are asking but, you can override the tostring method of your object

public override string ToString()
    {
        return string.Format("first:{0}, middle:{1} last:{2}", First, Middle, Last);
    }

then you can set it as the datasource of a control.

sadboy
+1  A: 
Name n = new Name { First = "test", Last = "last", Middle = "midddle" };
        textBox1.DataBindings.Add("Text", n, "First");
sadboy
+1  A: 

You want a "Data Source", specifically an "object data source".

This will get you started, from the "Data" menu, select "Add New Data Source..." You want to select "Object".

Data Source Configuration Wizard at http://msdn.microsoft.com/en-us/library/w4dd7z6t(VS.80).aspx.

How to: Connect to Data in an Object at http://msdn.microsoft.com/en-us/library/5xf878ky.aspx.

AMissico