2013-04-24 68 views
0

我想建立一個程序的組合列表來填充應用程序列表的組合框。它不斷嘔吐「不能綁定到新的顯示部件參數名:newDisplayMember」綁定到新成員顯示; BuildComboList

private void BuildComboList() 
    { 
     Applicant defaultApplicant = new Applicant(); 

     applicationList = defaultApplicant.GetList(); 
     applicantList.DataSource = applicationList; 
     applicantList.DisplayMember = "DisplayName"; 
     applicantList.ValueMember = "DisplayValue"; 
    } 

申請人類

public class Applicant 
{ 
    //Members 

    private int applicant_ID; 
    private string applicant_fname; 
    private string applicant_lname; 
    private string applicant_phone; 
    private string applicant_address1; 
    private string applicant_address2; 
    private string applicant_city; 
    private string applicant_state; 
    private string applicant_zip; 
    private string applicant_email; 



    //properties 

    public int Applicant_ID 
    { 
     get { return applicant_ID; } 
     set { applicant_ID = value; } 
    } 

    public string Applicant_fname 
    { 
     get { return applicant_fname; } 
     set { applicant_fname = value; } 
    } 

    public string Applicant_lname 
    { 
     get { return applicant_lname; } 
     set { applicant_lname = value; } 
    } 

    public string Applicant_phone 
    { 
     get { return applicant_phone; } 
     set { applicant_phone = value; } 
    } 

    public string Applicant_address1 
    { 
     get { return applicant_address1; } 
     set { applicant_address1 = value; } 
    } 

    public string Applicant_address2 
    { 
     get { return applicant_address2; } 
     set { applicant_address2 = value; } 
    } 

    public string Applicant_city 
    { 
     get { return applicant_city; } 
     set { applicant_city = value; } 
    } 

    public string Applicant_state 
    { 
     get { return applicant_state; } 
     set { applicant_state = value; } 
    } 

    public string Applicant_zip 
    { 
     get { return applicant_zip; } 
     set { applicant_zip = value; } 
    } 

    public string Applicant_email 
    { 
     get { return applicant_email; } 
     set { applicant_email = value; } 
    } 

    //Constructors 

    private void DefaultValues() 
    { 
     applicant_ID = 0; 
     applicant_fname = ""; 
     applicant_lname = ""; 
     applicant_phone = ""; 
     applicant_address1 = ""; 
     applicant_address2 = ""; 
     applicant_city = ""; 
     applicant_state = ""; 
     applicant_zip = ""; 
     applicant_email = ""; 
    } 

    private void Rec2Members(ApplicantRecord record)//defined in ApplicantDL 
    { 
     applicant_ID = record.applicant_ID; 
     applicant_fname = record.applicant_fname; 
     applicant_lname = record.applicant_lname; 
     applicant_phone = record.applicant_phone; 
     applicant_address1 = record.applicant_address1; 
     applicant_address2 = record.applicant_address2; 
     applicant_city = record.applicant_city; 
     applicant_state = record.applicant_state; 
     applicant_zip = record.applicant_zip; 
     applicant_email = record.applicant_email; 
    } 

    public ApplicantRecord ToRecord() 
    { 
     ApplicantRecord record = new ApplicantRecord(); 

     record.applicant_ID = applicant_ID; 
     record.applicant_fname = applicant_fname; 
     record.applicant_lname = applicant_lname; 
     record.applicant_phone = applicant_phone; 
     record.applicant_address1 = applicant_address1; 
     record.applicant_address2 = applicant_address2; 
     record.applicant_city = applicant_city; 
     record.applicant_state = applicant_state; 
     record.applicant_zip = applicant_zip; 
     record.applicant_email = applicant_email; 

     return record; 
    } 

    public List<ApplicantRecord> GetList() 
    { 
     return Approval_Form.ApplicantRecord.ApplicantDL.GetList(); 
    } 

    public void Insert() 
    { 
     applicant_ID = Approval_Form.ApplicantRecord.ApplicantDL.Insert(applicant_fname, applicant_lname, applicant_phone, applicant_address1, applicant_address2, applicant_city, applicant_state, applicant_zip, applicant_email); 
    } 

    public void Select(int applicant_ID) 
    { 
     ApplicantRecord record = Approval_Form.ApplicantRecord.ApplicantDL.Select(applicant_ID); 
     Rec2Members(record); 
    } 

    public void Update() 
    { 
     if (applicant_ID != 0) 
     { 
      Approval_Form.ApplicantRecord.ApplicantDL.Update(applicant_ID, applicant_fname, applicant_lname, applicant_phone, applicant_address1, applicant_address2, applicant_city, applicant_state, applicant_zip, applicant_email); 
     } 
    } 
} 
+0

您正在使用什麼平臺? (WPF,SilverLight,ASP.NET,...)你能告訴我們申請人級的代碼嗎? – Kenneth 2013-04-24 17:12:23

+0

使用visual c#,剛添加申請人類 – user2316654 2013-04-24 17:18:51

回答

0

我覺得應該是:

private void BuildComboList() 
{ 
    Applicant defaultApplicant = new Applicant(); 

    applicationList = defaultApplicant.GetList(); 
    applicantList.DataSource = applicationList; 
    applicantList.DisplayMember = "Applicant_fname"; 
    applicantList.ValueMember = "Applicant_ID"; 
} 

您可以更改申請人級別如下:

  1. 添加兩個屬性。

    公共字符串顯示名稱 { 得到{(applicant_fname + 「」 + applicant_lname;}}

    公共字符串DisplayValue { 得到{(applicant_ID.ToString();}}

  2. 保持的數據作爲綁定:

    私人無效BuildComboList() { 申請人defaultApp licant =新申請人();

    applicationList = defaultApplicant.GetList(); 
    applicantList.DataSource = applicationList; 
    applicantList.DisplayMember = "DisplayName"; 
    applicantList.ValueMember = "DisplayValue"; 
    

    }

+0

它彈出同樣的錯誤,我評論了 applicantList.ValueMember =「Applicant_ID」; 我評論完後,它拉起了下一個窗口。 – user2316654 2013-04-24 17:42:54

+0

你能提供你正在得到的確切的錯誤或這適用於你? – Abhinav 2013-04-24 17:50:26

+0

讓它能夠處理那段代碼。萬分感謝 – user2316654 2013-04-24 18:05:02