ahmed salah

ahmed salah

  • NA
  • 530
  • 148.9k

How to make default value for combobox with selectedvalue=0

Jan 24 2017 8:27 AM
Hi i work in visual studio 2015 with c# windows form
i need to assign default value with value 0 and text select to combox
but How can i do that ?
In windows form load i make 
  1.  var fileName = string.Format("{0}\\Book3105", Directory.GetCurrentDirectory());  
  2.             var connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0};Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;", fileName);  
  3. OleDbConnection con = new OleDbConnection(connection);  
  4.   
  5.             try  
  6.             {  
  7.                 con.Open();  
  8.                 str = "select * from [sheet2$]";  
  9.                 com = new OleDbCommand(str, con);  
  10.                 oledbda = new OleDbDataAdapter(com);  
  11.                 ds = new DataSet();  
  12.                 oledbda.Fill(ds, "[sheet2$]");  
  13.                 con.Close();  
  14.   
  15.                 dt = ds.Tables["[sheet2$]"];  
  16.                 int i = 0;  
  17.                   
  18.                  
  19.                 for (i = 0; i <= dt.Rows.Count - 1; i++)  
  20.                 {  
  21.         
  22.                     comboBox4.Items.Add(dt.Rows[i].ItemArray[1]);  
  23.                 }  
  24.             }  
  25.             catch (Exception ex)  
  26.             {  
  27.                 MessageBox.Show(ex.Message);  
  28.             }  
I can get data from Excel 2007 xlsx file but cannot assign default value --select-- with selected value 0
How to do that if possible 
 

Answers (3)