0

我正在尝试为程序构建一个组合列表,以用应用程序列表填充组合框。它不断抛出“无法绑定到新的显示成员。参数名称:newDisplayMember”

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);
        }
    }
}
4

1 回答 1

0

我认为应该是:

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

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

您可以进一步更改申请人类别,如下所示:

  1. 添加两个属性。

    公共字符串 DisplayName { get { return (applicant_fname + " " +applicant_lname; } }

    公共字符串 DisplayValue { get { return (applicant_ID.ToString(); } }

  2. 保持数据绑定为:

    私人无效BuildComboList(){申请人defaultApplicant =新申请人();

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

    }

于 2013-04-24T17:30:07.773 回答