C# - 在ListBox组件中使用displaymember设置两个属性

时间:2018-01-12 23:47:25

标签: c# listbox

我尝试显示" FirstName"和"姓氏"我的ListBox组件中的属性就像这样#34; SMITH Robert"但是当我启动程序时,我有Id属性。问题可能是该程序没有找到属性" LastName"和" FirstName" ...

我的客户类:

public class Customer
{
    private int id;
    private string lastName;
    private string firstName;

    public Customer(int id, string lastName, string firstName)
    {
        this.id = id;
        this.lastName = lastName.ToUpper();
        this.firstName = firstName;
    }

    #region Accessors

    public int GetId() { return id; }
    public string GetLastName() { return lastName; }
    public string GetFirstName() { return firstName; }

    public void SetId(int id) { this.id = id; }
    public void SetLastName(string lastName) { this.lastName = lastName; }
    public void SetFirstName(string firstName) { this.firstName = firstName; }

    #endregion

    #region Properties

    public int Id { get { return id; } set { id = value; } }
    public string LastName { get { return lastName; } set { lastName = value; } }
    public string FirstName { get { return firstName; } set { firstName = value; } }

    #endregion
}

我将用于此操作的功能(客户是从 Access 数据库加载的客户列表(此部分工作)):

// Define where is from data.
lbxCustomers.DataSource = customers;
// Value show in listbox.
lbxCustomers.DisplayMember = "LastNameFirstName";
// Value when row is selected in listbox.
lbxCustomers.ValueMember = "Id";

1 个答案:

答案 0 :(得分:4)

您需要将DisplayMember信息作为引用类中的现有属性:

// Reset Password Token link :get
router.get('/users/reset-password/:token', function(req, res) {
  User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, function(err, user) {
    if (!user) {
      req.flash('error', 'Password reset token is invalid or has expired.');
      return res.redirect('/users/new-password');
    }

    res.redirect('/users/reset-password', {
      user: req.user
    });
  });
});