20161014006 DataGridView Combobox Data binding and value transfer

Source: Internet
Author: User

Combobox
private void T_form_cy_cbd_d_currentcellchanged (object sender, EventArgs e)
{
DataGridViewCell Currnetcell = T_form_cy_cbd_d.currentcell;
t_form_cy_cbd_d.columns["Dfworkrate"]. ReadOnly = true;
if (Currnetcell! = null && CurrnetCell.OwningColumn.Name = = "Dfdevice")
{
Try
{
Rectangle rect = T_form_cy_cbd_d.getcelldisplayrectangle (T_Form_CY_CBD_D.CurrentCell.ColumnIndex, T_form_cy_cbd_d. Currentcell.rowindex, false);
String sexvalue = T_Form_CY_CBD_D.CurrentCell.Value.ToString ();

                     string str_sql = "SELECT [Fmachinetype],[fmpworkrate] from [PLM]. [dbo]. [T_form_cy_rateofwork_d] ";
                     DataTable DT2 = Plmdal. Dbhelper.execsql (str_sql);

                     datagridviewcomboboxcolumn CBO = (datagridviewcomboboxcolumn) t_form_cy_cbd_d.columns["DFDevice"];
                     CBO. Displaystyle = datagridviewcomboboxdisplaystyle.nothing;
                     CBO. DataSource = DT2;
                     CBO. DisplayMember = "Fmachinetype";
                     CBO. ValueMember = "Fmachinetype";

if (CurrnetCell.Value.ToString (). Trim ()! = "")
{
datarow[] Dr = Dt2. Select ("Fmachinetype = '" + CurrnetCell.Value.ToString (). Trim () + "'");
MessageBox.Show (Dr[0]. ITEMARRAY[1]. ToString (). Trim ());
t_form_cy_cbd_d.currentrow.cells["Dfworkrate"]. Value = dr[0]. ITEMARRAY[1]. ToString (). Trim ();
}

String selectvalue = (string) (T_form_cy_cbd_d.currentcell as DataGridViewComboBoxCell). value;//the key that obtains the selected value is the value of the binding ValueMember.
MessageBox.Show ("" + selectvalue.tostring () + "");
MessageBox.Show (CurrnetCell.Value.ToString ());

//
DataGridViewComboBoxCell Dgvcell = T_form_cy_cbd_d.rows[e.rowindex]. Cells[1] as DataGridViewComboBoxCell;
DataGridViewComboBoxCell Dgvcell = T_form_cy_cbd_d.currentcell as DataGridViewComboBoxCell;
Dgvcell.datasource = DT2. Rows[0][0]. ToString ();
Dgvcell.displaymember = "Measurename";
Dgvcell.valuemember = "Measureid";

                    //string selectvalue = (string) (T_form_cy_cbd_d.currentcell as DataGridViewComboBoxCell). value;//the key that obtains the selected value is the value of the binding ValueMember.
                    //messagebox.show ("" + selectvalue.tostring () + "");
               }
                catch (Exception Ex)
                {
                     MessageBox.Show (ex. ToString ());
               }

}
}

20161014006 DataGridView Combobox Data binding and value transfer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.