I have an excel file which has two columns (1. Name and 2. Value) which I want to bind to a ComboBox.
When I set the DisplayMember
to name it shows the all the values from the Name column in the Excel file.
I would like to get a similar dropdown as in asp.net controls with a text field and a value field so that when I select the text field then value field can be obtained using background code.
How can I do in ComboBox(WinForms)?
i am using following code.
String strConn = "Provider=Microsoft.jet.OLEDB.4.0;" + "Data Source="C:vipin.xls"+ "Extended Properties=Excel 8.0;";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT [name] FROM [Sheet1$] where Component=1 ", strConn);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
comboBox1.DataSource = ds.Tables[0].DefaultView;
comboBox1.DisplayMember = "name";
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…