ComboBox.ValueMember and DisplayMember

后端 未结 8 1558
野的像风
野的像风 2020-12-06 12:45

How do i set this values? I have a DataTable with all the data i want to set in the combobox, but i cant find how to set it.

I tried

ComboBox1.DataSo         


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-06 13:31

    ComboBox1.ValueMember = dataTable.Columns["id"].ColumnsName;   // column name which the values are not visible 
    ComboBox1.DisplayMember = dataTable.Columns ["name"].ColumnsName;
     /* 
           column name that you need to select item by proprity : 
    ComboBox1.SelectedItem; 
    Or   you can use easly this : 
    ComboBox1.Text; 
    */
    
    ComboBox1.DataSource= dataTable; //the data table which contains data 
    // and this should be last :)
    

提交回复
热议问题