1. 程式人生 > >DataGridView中單元格Cell改變事件

DataGridView中單元格Cell改變事件

cells .get control 控件 type win end bject pri

DataGridView控件中的各種事件都無法直接響應Cell中內容的變化,包括KeyPress等事件,可以采用下面方法

無法響應Cell中的回車鍵

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;

}

DataGridView中單元格Cell改變事件