Combobox Selected Values...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chinni1
    New Member
    • Nov 2008
    • 24

    Combobox Selected Values...

    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.....

    Code:
     da = new SqlDataAdapter("select * from main_products", con);
                da.Fill(ds, "main");
                da = new SqlDataAdapter("select * from sub_master", con);
                da.Fill(ds, "sub");
    
    
              
                comboBox1.DataSource = ds.Tables["main"];
                comboBox1.DisplayMember = "prod_name";
                comboBox1.ValueMember = "prod_id";
    
    
    ///In combobox selected index changed
    
    			DataView dv = new DataView(ds.Tables["sub"]);
                    dv.RowFilter = "prod_id=" + comboBox1.SelectedValue;
                    comboBox2.DataSource = dv;
                    
                  
                    comboBox1.ValueMember = "prod_id";
    IM getting In first combobox the Main products values,but In second Combobox System.Data.Dat aRowView is displying insted of related subproducts.

    Thanks
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    I think you've to set DisplayMember and ValueMember for comboBox2 too.

    Comment

    • chinni1
      New Member
      • Nov 2008
      • 24

      #3
      Originally posted by ChBinder
      I think you've to set DisplayMember and ValueMember for comboBox2 too.
      Hii...

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

      Thanks

      Comment

      • Christian Binder
        Recognized Expert New Member
        • Jan 2008
        • 218

        #4
        DId you change your code?
        Code:
        comboBox1.DataSource = ds.Tables["main"];
        comboBox1.DisplayMember = "prod_name";
        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?

        Comment

        • chinni1
          New Member
          • Nov 2008
          • 24

          #5
          Originally posted by ChBinder
          DId you change your code?
          Code:
          comboBox1.DataSource = ds.Tables["main"];
          comboBox1.DisplayMember = "prod_name";
          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?
          No,I did not changed anything in code,but its dispaying prod_id only

          Comment

          Working...