How to append two field values in combobox display member in C#

后端 未结 7 674
死守一世寂寞
死守一世寂寞 2020-12-30 02:43

In my table, I have a field of firstname and lastname, now what I want is to set firstname and lastname as displaym

7条回答
  •  难免孤独
    2020-12-30 03:32

    in C# 6 create readonly property in your Employee class

    public string FullName=>$"{lastname} {firstname}";
    

    then

    cmbEmployees.DataSource = GetEmployees();
    //something like below line which doesn't work
    cmbEmployees.DisplayMember = "FullName";     
    cmbEmployees.ValueMember = "id";
    

提交回复
热议问题