c# - how to load data into combobox from datagridview -


i want load data datagridview combobox in form update problem specific item not being selected in productname combobox against productid solution please help

// code of gridview form        private void invoiceitemsdetailsdatagridview_doubleclick(object sender, eventargs e)     {         int index = invoiceitemsdetailsdatagridview.rows.getfirstrow(datagridviewelementstates.selected);         //string productid = invoiceitemsdetailsdatagridview.rows[index].cells["productid"].value.tostring();         //string productname = invoiceitemsdetailsdatagridview.rows[index].cells["productname"].value.tostring();          invoiceitemdetailchangeform icf = new invoiceitemdetailchangeform();         icf.currentquantity = convert.touint16(invoiceitemsdetailsdatagridview.rows[index].cells["quantity"].value);         icf.productid = convert.touint16(invoiceitemsdetailsdatagridview.rows[index].cells["productid"].value); ;         icf.showdialog();     } 

// class level declared int in invoiceitemdetailchangeform update

    public int currentquantity { get; set; }      public int productid { get; set; } 

// code related combobox in invoiceitemdetailchangeform form

    private void invoiceitemdetailchangeform_load(object sender, eventargs e)     {         qtytextbox.text = currentquantity.tostring();         productnamecombobox.selectedvalue = productid;          productnamecombobox.displaymember = "productname";         productnamecombobox.valuemember = "productid";         productnamecombobox.datasource = getallproducts();         //productnamecombobox.selectedvalue = -1;      }      private object getallproducts()     {         datatable dtproducts = new datatable();         string connstring = configurationmanager.connectionstrings["dbz"].connectionstring;         using (sqlconnection conn = new sqlconnection(connstring))         {             using (sqlcommand cmd = new sqlcommand("usp_getallproductsforpos", conn))             {                 cmd.commandtype = commandtype.text;                 conn.open();                  sqldatareader reader = cmd.executereader();                 dtproducts.load(reader);             }         }         return dtproducts;     } 

you setting selected value before binding have move after bind

try this

private void invoiceitemdetailchangeform_load(object sender, eventargs e)     {         qtytextbox.text = currentquantity.tostring();           productnamecombobox.displaymember = "productname";         productnamecombobox.valuemember = "productid";         productnamecombobox.datasource = getallproducts();         //productnamecombobox.selectedvalue = -1;         productnamecombobox.selectedvalue = productid;      } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -