ComboBox.ValueMember and DisplayMember

后端 未结 8 1554
野的像风
野的像风 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:30
      ComboBox1.DataSource= dt; //the data table which contains data
      ComboBox1.ValueMember = "id";   // column name which you want in SelectedValue
      ComboBox1.DisplayMember = "name"; // column name that you need to display as text
    
    0 讨论(0)
  • 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 :)
    
    0 讨论(0)
提交回复
热议问题