我想在一个comboBox中显示很多列。
我试过这个:
da = new SqlDataAdapter("select * from do_data",cn);
da.Fill(dt3);
comboBox1.DataSource = dt3;
comboBox1.DisplayMember = "fname+lname";
comboBox1.ValueMember = "id";
但它没有显示两个列,它显示了' ValueMember'。
怎么做?
答案 0 :(得分:2)
试试这个
da = new SqlDataAdapter("select id,fname + ' ' + lname As Name from do_data",cn);
da.Fill(dt3);
comboBox1.DataSource = dt3;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "id";
如果您想要所有列,请尝试以下
da = new SqlDataAdapter("select *,fname + ' ' + lname As Name from do_data",cn);
da.Fill(dt3);
comboBox1.DataSource = dt3;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "id";
答案 1 :(得分:0)
您可以添加computed column并将其设置为显示成员
dt3.Columns.Add("Combined", typeof(string), "fname+' '+ fname");
comboBox1.DataSource = dt3;
comboBox1.DisplayMember = "Combined";
comboBox1.ValueMember = "id";