ahmed salah

ahmed salah

  • NA
  • 530
  • 149.8k

How to merge or combine two combobox in one comb box

Feb 4 2017 9:00 AM
I have two combo box controls

First combo box show Arabic membership

Second combo box show English member ship

I need to merge two combo box in one combo box show both of them

my code as below

MemberAR sheet and MemberEN sheet have two fields
MemberID , MemberName 
  1. public DataTable ShowExcelDataArabic()  
  2.         {  
  3.              
  4.             OleDbConnection con = new OleDbConnection(connection);  
  5.   
  6.              
  7.                 con.Open();  
  8.                string str = "select * from [MemberAR$]";  
  9.                 OleDbCommand com = new OleDbCommand();  
  10.                 com = new OleDbCommand(str, con);  
  11.                 OleDbDataAdapter oledbda = new OleDbDataAdapter();  
  12.                 oledbda = new OleDbDataAdapter(com);  
  13.                 DataSet ds = new DataSet();  
  14.                 ds = new DataSet();  
  15.                 oledbda.Fill(ds, "[MemberAR$]");  
  16.                 con.Close();  
  17.                 DataTable dt = new DataTable();  
  18.                 dt = ds.Tables["[MemberAR$]"];  
  19.                 return dt;  
  20.               
  21.              
  22.         }  
  23. public DataTable ShowExcelDataEnglish()  
  24.         {  
  25.   
  26.             OleDbConnection con = new OleDbConnection(connection);  
  27.   
  28.   
  29.             con.Open();  
  30.             string str = "select * from [MemberEN$]";  
  31.             OleDbCommand com = new OleDbCommand();  
  32.             com = new OleDbCommand(str, con);  
  33.             OleDbDataAdapter oledbda = new OleDbDataAdapter();  
  34.             oledbda = new OleDbDataAdapter(com);  
  35.             DataSet ds = new DataSet();  
  36.             ds = new DataSet();  
  37.             oledbda.Fill(ds, "[MemberEN$]");  
  38.             con.Close();  
  39.             DataTable dt = new DataTable();  
  40.             dt = ds.Tables["[MemberEN$]"];  
  41.             return dt;  
  42.   
  43.   
  44.         }  
 

in load event of windows form

 combo box Arabic membership and combo box English member ship as following :

 
  1. QrClasses qrc = new QrClasses();  
  2.                 DataTable dt = qrc.ShowExcelDataArabic();  
  3.                 int c = 0;  
  4.                 comboBox1.Items.Insert(0, "???? ?????");  
  5.                 comboBox1.SelectedIndex = 0;  
  6.                 for (c = 0; c <= dt.Rows.Count - 1; c++)  
  7.                 {  
  8.   
  9.                     comboBox1.Items.Add(dt.Rows[c].ItemArray[1]);  
  10.                 }  
  11.   
  12.   
  13.                 DataTable dt2 = qrc.ShowExcelDataEnglish();  
  14.                 int d = 0;  
  15.                 comboBox2.Items.Insert(0, "Select Member");  
  16.                 comboBox2.SelectedIndex = 0;  
  17.                 for (d = 0; d <= dt2.Rows.Count - 1; d++)  
  18.                 {  
  19.   
  20.                     comboBox2.Items.Add(dt2.Rows[d].ItemArray[1]);  
  21.                 }  



Answers (5)