如何加入丝束组合框数据

如何加入丝束组合框数据

问题描述:

我有两个组合框之一,并从两个不同的表的第一组合框代码数据负载是如何加入丝束组合框数据

> OleDbCommand cmd = new OleDbCommand("select empno,ename from emp", con); 
      OleDbDataReader dr = cmd.ExecuteReader(); 
      while (dr.Read()) 
      { 
       combobox1.Items.Add(dr[1].ToString()); 

      } 

结果:

KING 

BLAKE 

CLARK 

和第二组合框代码是

> OleDbCommand cmd1 = new OleDbCommand("select UnitId,UnitName from 
> TableUnit", con); 
>    OleDbDataReader dr1 = cmd1.ExecuteReader(); 
>    while (dr1.Read()) 
>    { 
>     combobox2.Items.Add(dr1[1].ToString()); 
>    } 

结果:

ACCOUNTING 

RESEARCH 

SALES 

OPERATIONS 

我怎么能有载荷数据加入这两个结果(combobox1 + combobox2)到combobox3如

KING ACCOUNTING 

BLAKE RESEARCH 

您可以按以下方式合并在第三组合框2个组合框的内容:

for (int i = 0; i < (combobox1.Items.Count < combobox2.Items.Count ? combobox1.Items.Count : combobox2.Items.Count); i++) 
{ 
     combobox3.Items.Add($"{combobox1.Items[i]} {combobox2.Items[i]}"); 
}