C# DataGridView中单元格Cell改变事件


DataGridView控件中的各种事件都无法直接响应Cell中内容的变化,包括KeyPress等事件,可以采用下面方法

private void dataGridViewBarcode_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control.GetType().Equals(typeof(DataGridViewTextBoxEditingControl)))
            {
                e.CellStyle.BackColor = Color.FromName("window");
                DataGridViewTextBoxEditingControl textControl = e.Control as DataGridViewTextBoxEditingControl;
                textControl.TextChanged += new EventHandler(textControl_TextChanged);
            }
        }

private void textControl_TextChanged(object sender, EventArgs e)
        {
            this.label1.Text = ((TextBox)sender).Text;
        }

 注:此方法无法响应Cell中的回车键


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM