2013-05-01 74 views
-2

也許標題是不正確的,但我沒有其他想法如何問。 我有一個窗體與多個選項卡,使用單身。以及我的表單大約有50多個文本框,它將用戶輸入存儲到我的單例屬性中,然後保存到xml中。我的問題是讀取xml並在文本框上顯示保存到xml中的簡單路徑是什麼? 示例代碼:多個文本框2方式綁定

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;等等,但你無法想象會佔用多少線路。

+0

這是的WinForms或WPF? – 2013-05-01 22:28:06

+0

窗體Dan Puzey。 – 2013-05-01 22:35:47

+0

然後,你最好的選擇可能是很多代碼行...... – 2013-05-01 22:36:48

回答

0

您可以綁定文本框兩路像這樣:

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

爲了進一步瞭解詳情 http://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings.aspx

+0

感謝您的快速響應,但仍然需要我爲每個文本框做,不是嗎? – 2013-05-01 22:40:09

+0

yes ofcourse :)。但它將用於雙向綁定,因此將保存代碼以將值綁定到數據集。 – 2013-05-01 22:44:14