码迷,mamicode.com
首页 > Windows程序 > 详细

DataGridView属性和事件

时间:2018-01-30 16:55:10      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:+=   tag   get   current   获取   pre   .text   end   void   

        //注册绑定事件
        private void dgvBidFile_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            DataGridView dataGridView = (DataGridView)sender;
            int columnIndex = dataGridView.CurrentCell.ColumnIndex;
            if (columnIndex == 3||columnIndex==5||columnIndex==6)
            {
                e.Control.KeyPress += new KeyPressEventHandler(TextBoxDec_KeyPress);
            }

            if (dataGridView.CurrentCell.GetType().Name == "DataGridViewComboBoxCell")
            {
                bidFileId = Convert.ToInt32(dataGridView.CurrentRow.Cells[this.colBidFileId.Index].Value);
                ComboBox comboBox = (ComboBox)e.Control;
                comboBox.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
        }


        //只输入数字判定事件。该事件是手动添加的绑定事件
        private void TextBoxDec_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != .)
            {
                e.Handled = true;
            }
        }

        //下拉框更改事件,该事件是手动添加的绑定事件
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
             ComboBox comboBox = (ComboBox)sender;
             //接下来获取下来框中的内容...
             //comboBox.Text为当前选定的下拉框的内容
        }


       //普通文本框更改事件
       private void dgvBidFile_CellValueChanged(object sender, DataGridViewCellEventArgs e)
       {
            if (e.ColumnIndex == this.colRemark.Index)
            {
                   //colRemark为数据绑定列
                   //发生什么事...
            }
       }

       

 

DataGridView属性和事件

标签:+=   tag   get   current   获取   pre   .text   end   void   

原文地址:https://www.cnblogs.com/AlexOneBlogs/p/8384033.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!