By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Combobox Selected Values...

P: 24
I Have 2 comboboxes in my form.The first combobox1 shoud be fill with the mainproduts which is cmng from database.By selecting The mainproduct the related sub product shoud dispaly in second combobox2.
In form load written this code.....

Expand|Select|Wrap|Line Numbers
  1.  da = new SqlDataAdapter("select * from main_products", con);
  2.             da.Fill(ds, "main");
  3.             da = new SqlDataAdapter("select * from sub_master", con);
  4.             da.Fill(ds, "sub");
  5.  
  6.  
  7.  
  8.             comboBox1.DataSource = ds.Tables["main"];
  9.             comboBox1.DisplayMember = "prod_name";
  10.             comboBox1.ValueMember = "prod_id";
  11.  
  12.  
  13. ///In combobox selected index changed
  14.  
  15.             DataView dv = new DataView(ds.Tables["sub"]);
  16.                 dv.RowFilter = "prod_id=" + comboBox1.SelectedValue;
  17.                 comboBox2.DataSource = dv;
  18.  
  19.  
  20.                 comboBox1.ValueMember = "prod_id";
  21.  
  22.  
IM getting In first combobox the Main products values,but In second Combobox System.Data.DataRowView is displying insted of related subproducts.

Thanks
Jun 10 '10 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 218
I think you've to set DisplayMember and ValueMember for comboBox2 too.
Jun 10 '10 #2

P: 24
@ChBinder
Hii...

Thanks ChBinder,its worked.But i want to display in first combobox1 mainproductname insted of id.In second combobox im getting name..

Thanks
Jun 10 '10 #3

Expert 100+
P: 218
DId you change your code?
Expand|Select|Wrap|Line Numbers
  1. comboBox1.DataSource = ds.Tables["main"];
  2. comboBox1.DisplayMember = "prod_name";
  3. comboBox1.ValueMember = "prod_id";
This would mean, that the combo-box displays the field prod_name. You say, the combo-box doesn't disply the prod_name but prod_id instead?
Jun 10 '10 #4

P: 24
@ChBinder
No,I did not changed anything in code,but its dispaying prod_id only
Jun 10 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.