Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please look at the following code:

C#
comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
     comboBox1.AutoCompleteMode = AutoCompleteMode.None;
     comboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
     comboBox1.DisplayMember = comboBox1.ValueMember = "Note";
     var myConn = new SqlConnection("...");
     var sqlStr = "SELECT Note FROM ...";
     var dAdapter = new SqlDataAdapter(sqlStr, myConn);
     DataTable dTable = new DataTable();
     dAdapter.Fill(dTable);
     dAdapter.Dispose();
     comboBox1.DataSource = dTable;


comboBox1 shows the result correctly but the Items filled with this string "{System.Data.DataRowView}" so i can't use them programmaticly.
Thanks for your help.
Posted
Updated 17-Nov-14 22:49pm
v2

comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
       SqlConnection conn = new SqlConnection(@"server=.\sqlexpress;database=test;Integrated Security=True");
       //conn.Open();
       comboBox1.AutoCompleteMode = AutoCompleteMode.None;
       comboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
       comboBox1.DisplayMember = comboBox1.ValueMember = "Note";

       DataTable t = new DataTable();
       SqlDataAdapter dap = new SqlDataAdapter("select note from notes",conn);
       dap.Fill(t);
       dap.Dispose();
       comboBox1.DataSource = t;

There's no problem in your code actually when you will not set
comboBox1.DisplayMember
property you will see
System.Data.DataRowView
But you have set those .So there is no problem in your code.Build Again and run.Hope it should work fine
 
Share this answer
 
I cast the item and get the correct result:

Quote:
var s = (comboBox1.Items[i] as DataRowView)[0];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900