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

}
        }

时间: 2024-08-25 14:04:47

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

WPF Combobox数据绑定Binding

combobox数据绑定List链表集合区分显示值与选择的值 整体效果: 根据combobox选择情况分别打印选取值与显示值 代码: Windows窗体: 1 <Window x:Class="ComboxBinding.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.

WinForm 控件ComboBox数据绑定

ComboBox下拉菜单控件,在数据库内的ComboBox应用的表进行修改时,如果是用的普通方法,显示数据一个方法,添加数据一个方法 这样会导致程序后期维护难度增加,在这里使用数据绑定来让ComboBox数据实现根据数据库对应表数据显示,降低数据维护难度. 1.首先将要ComboBox所需要的表的数据全部查询出来 2.对查询获得的数据用实例化泛型集合List进行接收 3.设置需要显示的列[数据] 4.设置对数据库操作需要的列[数据] 示例: public Form3() //窗体打开自动执行的数

WPF的ComboBox数据绑定,使用Dictionary作为数据源

ViewModel//属性定义     Dictionary<int, string> _selGroupList;        /// <summary>        /// 分组下拉列表        /// </summary>        public Dictionary<int, string> selGroupList        {            get { return _selGroupList; }           

DataGridView中的Combobox的应用

在WinForm中DataGridView可谓是应用比较多的数据显示控件了,DataGridView中可以应用各种控件,关于这样的文章网上 已有很多.都是实例化一个控件然后通过DataGridView.Controls.Add()方法绑定控件.然后通过特定的事伯执行数据绑定与操作. 这几天在做项目的时候也也用到的DataGridView控件,而且需要要DataGridView使用ComboBox来动态的显示数据.查了不少 的资料来完成DataGridView中的ComboBox的数据绑定,多数都

c#dataGridView 知识

一.单元格内容的操作 // 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index Console.WriteLine(DataGridView1.CurrentCell.ColumnIndex); // 取得当前单元格的行 Index Console.WriteLine(DataGridView1.CurrentCell.RowIndex); 另外,使用 DataGridView.Curr

DataGridView控件-[引用]

DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特性. 关于本文档: 本文档不准备面面俱到地介绍DataGridView,而是着眼于深入地介绍一些技术点的高级特性. 本文档按逻辑分为5个章节,首先是结构和特性的概览,其次是内置的列/单元格类型的介绍,再次是数据操作相关的内容,然后是主要特性的综述,最后是最佳实践. 大部分章节含有一个"Q &

FrameWork:winform以及正则表达式基础

Winform201611041.常用控件 Label 标签 lblXXX Name TextTextBox 文本框 txtXXX Name Text PasswordChar MultiLine Button 按钮 btnXXX Name Text MenuStrip:菜单 ToolStrip:工具条 GroupBox:分组框 grpRadioButton:单选按钮 rdb CheckedComboBox:组合框 cbb DropDownStyle:DropDownListDateTimePi

.net窗体程序的基础知识及详细笔记

第一章:初识Windows程序 1.1:第一个wondows程序 1.1.1:认识windows程序 Form1.cs:窗体文件:程序对窗体编写的代码一般都存放在这个文件(还有拖动控件时的操作和布局,还有设置一般的属性)      F4:跳到设置属性的界面  F7:跳到逻辑代码文件 From.Designer.cs:窗体设计文件:一般拖动控件自动生成的文件(很少修改) From.resx:资源文件:配置图片等资源. Program.cs: 主程序文件:包含main方法的程序入口,如果要改执行的窗

winfrom 窗体控件实现二级联动

事件,而这个时候用户并没有选择内容,其SelectedValue也不是对应字段的值.那么时写在SelectedIndexChanged中的处理代码就会因为SelectedValue的内容不正确引发异常.一般网上找到的方法是添加一个标记位,在绑定前设置为false,绑定完成后设置回true. 绑定到ComboBox void BindComboBox() { flag=false; ComboxBox1.ValueMember="ValueColumn"; ComboxBox1.Disp