zoukankan      html  css  js  c++  java
  • 20161014006 DataGridView Combobox 数据绑定与传值

            //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;//取得所选值的key即绑定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;//取得所选值的key即绑定ValueMember的值。
                        //MessageBox.Show("" + selectValue.ToString() + "");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }

                }
            }

  • 相关阅读:
    深度分析HTML5在移动开发方面的发展状况
    腾讯实习生笔试题
    更简洁的 CSS 清理浮动方式
    图片垂直居中的使用技巧
    Css Reset(复位)整理
    70565 Pro: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 考试感言
    Android SDK 有bug
    70540 TS: Microsoft Windows Mobile 5.0 Application Development 考试感言
    70565 Pro: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 考试感言
    TS:70503 Windows Communication Foundation TS: 70505 Windows Form Application Dev 考试感言
  • 原文地址:https://www.cnblogs.com/hutie1980/p/5960847.html
Copyright © 2011-2022 走看看