//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());
                }

}
        }

20161014006 DataGridView Combobox 数据绑定与传值的更多相关文章

  1. C# WinForm 中ComboBox数据绑定的问题 (转)

    来自:http://blog.sina.com.cn/s/blog_5fb9e26301013wga.html C# WinForm 中ComboBox数据绑定的问题 怎样让WinForm中的Comb ...

  2. combobox数据绑定

    jquery easyui datagrid 可编辑行 combobox数据绑定问题 将带有参数的url地址赋值给变量,然后将变量赋值给url <script type="text/j ...

  3. WPF Combobox数据绑定 Binding

    combobox数据绑定List链表集合区分显示值与选择的值 整体效果: 根据combobox选择情况分别打印选取值与显示值 代码: Windows窗体: <Window x:Class=&qu ...

  4. C# 控件,MenuStrip,statusStrip,contextMenuStrip,ImageList, Listview,MonthCalendar、DataGridView,combobox,textbox,DateTimePicker,treeview,picturebox、toolStrip,radioButton,TableLayoutPanel

    一.菜单栏 1)MenuStrip 菜单栏 选择工具栏控件:menuStrip C# Menustrip控件的常用属性用法详解 C#WinForm应用程序——添加菜单栏MenuStrip] 1.通过右 ...

  5. WinForm DataGridView双向数据绑定

    程序目标: 实现DataGridView与BindingList<T>双向绑定.用户通过DataGridView修改值后立即更新BindList对象的值,代码修改BindList后立即更新 ...

  6. MVVM模式WPF的ComboBox数据绑定,使用Dictionary作为数据源

    ViewModel//属性定义 Dictionary<int, string> _selGroupList; /// <summary> /// 分组下拉列表 /// < ...

  7. WPF combobox数据绑定和数据获取

    本文章仅为个人学习,如有错误之处请指正. 搭建WPF界面的时候,想用combobox构建一个下拉菜单,搜索的时候看到大多数都是大段代码,逻辑顺序不是很详细,摸索了大概,记录一下方便来者. 拖入comb ...

  8. DataGridView中的Combobox的应用

    在WinForm中DataGridView可谓是应用比较多的数据显示控件了,DataGridView中可以应用各种控件,关于这样的文章网上 已有很多.都是实例化一个控件然后通过DataGridView ...

  9. C#: 数据绑定

    数据绑定是分离UI和后端主逻辑程序的一种好的办法.这里总结下TextBox, Label, ComboBox, ListBox, DataGridView的数据绑定 数据绑定都是通过DB来和UI控件的 ...

随机推荐

  1. 键盘事件触发的兼容tips

    在firefox中 退格键 enter del tab 这些非字符触发编码为0 然而在Safari3以下 是8

  2. wifi破解实践截图

  3. css线性渐变--linear-gradient

    使用css直接写渐变,对于现在而言,应该属于比价简单的一件事了,在一定程度上,扁平化的设计趋势的出现,减少了使用渐变色的场景,但是并不影响我们逐渐的熟悉线性渐变Linear-gradient的写法. ...

  4. window的对象有哪些(笔记)

    window的主对象主要有如下几个: document 对象: frames 对象: history 对象: location 对象: navigator 对象: screen 对象: 全局变量和函数 ...

  5. imx6 关闭调试串口

    需要关闭imx6调试串口,用作普通的串口使用. 参考链接 http://blog.csdn.net/neiloid/article/details/7585876 http://www.cnblogs ...

  6. [转]SQL SERVER – Importance of Database Schemas in SQL Server

    原文地址http://blog.sqlauthority.com/2009/09/07/sql-server-importance-of-database-schemas-in-sql-server/ ...

  7. Single Responsibility Principle 单一职责原则

  8. Eclipse中配置svn

    1.打开eclipse,help--> Eclipse MarketPlace...,搜索输入“subclipse”,点击安装,一路按向导安装: 2.安装成功后,在Window --> S ...

  9. 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099;

     错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is:  java ...

  10. handler发消息的形式

    1.onCreate()中写好handler的接受机制,准备接受并处理消息 2.thread中利用handler.post(Runnable r): protected void onCreate(B ...