Click here to Skip to main content
15,898,978 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one data gridview with commodities names and their id's..when i select a record i need to display selected name in the combobox....if i click on dropdown , the rest of the names to displayed for updating the value...i am using two tables..one for getting edited record from the database and other for the binding remaining names....data coming to the tables...but second table is only binding....selected value is not displaying at the top..

What I have tried:

C#
if (varietyid != 0 && op_mode == "Edit")
                {
                    btnSave.Text = "Modify";
                    op_mode = "Edit";
                    mode = 6;         
                   
                    cmdVrty = objVariety.getCommodityAndVariety(mode,varietyid,cid);

                    int cnt;
                    cnt = cmdVrty.Rows.Count;
                   

                    for (int i = 0; i < cnt - 1; i++)
                    {
                        DataRow row;
                        row = cmdVrty.NewRow();
                        row["commodity"] = cmdVrty.Rows[0]["NAME"].ToString();
                        row["cid"] = Convert.ToInt32(cmdVrty.Rows[0]["COMMODITYID"]);
                      
                        cmdVrty.Rows.InsertAt(row, 0);
                        cmbCommodity.DataSource = cmdVrty;
                        cmbCommodity.DisplayMember = "commodity";
                        cmbCommodity.ValueMember = "cid";
                      
                      

                    bindcmbforedit();
}

  public void bindcmbforedit()
        {
            mode = 6;

            bindTable = objVariety.getVarietybyCommodity();
            cmbCommodity.DataSource = bindTable ;
            cmbCommodity.DisplayMember = "NAME";
            cmbCommodity.ValueMember = "ID";
       }
Posted
v2

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