多列组合框

时间:2013-11-01 06:13:37

标签: c# winforms combobox

我在组合框中使用多列。所以,我想在 stock_type stock_type_dscription 之间加一个空格。我尝试了以下编码,但组合框中的所有项目都替换为 system.data.datarowview

 string sqlstk = "SELECT stock_type, stock_type_desc FROM stktype";
 SqlCommand stkcom = new SqlCommand(sqlstk, myconnection);

 SqlDataAdapter dastk = new SqlDataAdapter(stkcom);
 DataSet1 dsstk = new DataSet1();
 dastk.Fill(dsstk, "StockType");

 cboStk.DisplayMember = "stock_type" + " " +"stock_type_des";
 cboStk.ValueMember = "stock_type" + " " + "stock_type_des";
 cboStk.DataSource = dsstk.Tables["StockType"];

任何人都知道在多列组合框中放置空间的方法,请帮助和指导。 提前致谢

1 个答案:

答案 0 :(得分:3)

我会改变sql语句,如下所示

 string sqlstk = "SELECT stock_type + ' ' +stock_type_des as combined FROM stktype";

然后

 cboStk.DisplayMember = "combined";
 cboStk.ValueMember = "combined";