多个文本框2路绑定

时间:2013-05-01 22:15:59

标签: c# textbox

也许标题不正确,但我对如何提问没有其他想法。 我有一个窗口表单,其中包含多个使用单例的选项卡。好吧,我的表单有大约50多个文本框,用于将用户输入存储到我的单例属性,然后保存到xml。我的问题是,阅读xml并在文本框中显示保存到xml的内容的复杂路线是什​​么? 示例代码:

public class ContactInfo
   {
    public string Name { get { return Firstname + " " + LastName; } }

    public string Firstname { get; set; }

    public string LastName { get; set; }

    public string PhoneNumber { get; set; }

    public string Email { get; set; }

    public string Address1 { get; set; }

    public string Address2 { get; set; }

    public string City { get; set; }

    public string State { get; set; }

    public string ZipCode { get; set; }
   }
public class Site
{
Site()
 {
        OfficeAddress = new ContactInfo();
        ShippingAddress = new ContactInfo();
        DirectorOfOperationsFandB = new ContactInfo();
        DirectorOfOperationsRetail = new ContactInfo();
        SecondInCharge = new ContactInfo();
        SiteController = new ContactInfo();
        SiteContact = new ContactInfo();
  }
    public ContactInfo OfficeAddress { get; set; }

    public ContactInfo ShippingAddress { get; set; }

    public ContactInfo DirectorOfOperationsFandB { get; set; }

    public ContactInfo DirectorOfOperationsRetail { get; set; }

    public ContactInfo SecondInCharge { get; set; }
  }

我开始做textbox1.text = Site.OfficeAdress.Address1;等等,但你无法想象会占用多少行。

1 个答案:

答案 0 :(得分:0)

您可以像这样绑定textBox:

textBox1.DataBindings.Add(new Binding("Text", ds, "customers.custName"));

了解更多详情 http://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings.aspx