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