WinForms combobox with multiple columns (C#)?

前端 未结 11 2023
轮回少年
轮回少年 2020-12-01 21:19

I am using currently the following code to populate a combobox:

combobox.DataSource = datatable;
combobox.DisplayMember = \"Auftragsnummer\";
combobox.ValueM         


        
11条回答
  •  有刺的猬
    2020-12-01 21:50

    You can add to your dataset a dummy column (Description) and use that as DisplayMember in the combo box databinding.

    SELECT Users.*, Surname+' '+Name+' - '+UserRole AS Description FROM Users
    
    ComboBox.DataBindings.Add(new Binding("SelectedValue", bs, "ID"));
    ComboBox.DataSource = ds.Tables["Users"];
    ComboBox.DisplayMember = "Description";
    ComboBox.ValueMember = "ID";
    

    Simple and works.

提交回复
热议问题