datagridview 单元格内容实时变化事件

  
    
private void dataGridView1_EditingControlShowing( object sender, DataGridViewEditingControlShowingEventArgs e)
{
// if (e.Control.GetType().Equals(typeof(DataGridViewComboBoxEditingControl))) // cell为类ComboBox时
// {
// e.CellStyle.BackColor = Color.FromName("window");
// DataGridViewComboBoxEditingControl editingControl = e.Control as DataGridViewComboBoxEditingControl;
// editingControl.SelectedIndexChanged += new EventHandler(editingControl_SelectedIndexChanged);
// }
if (e.Control.GetType().Equals( typeof (DataGridViewTextBoxEditingControl))) // cell为类TextBox时
{
e.CellStyle.BackColor
= Color.FromName( " window " );
DataGridViewTextBoxEditingControl editingControl
= e.Control as DataGridViewTextBoxEditingControl;
editingControl.TextChanged
+= new EventHandler(editingControl_TextChanged);
}
}

// TextBox的TextChanged事件
private void editingControl_TextChanged( object sender, EventArgs e)
{
this .label1.Text = dataGridView1.CurrentCell.EditedFormattedValue.ToString();
}

/// /Combox的SelectedIndexChanged事件
// void editingControl_SelectedIndexChanged(object sender, EventArgs e)
// {
// this.label1.Text = dataGridView1.CurrentCell.EditedFormattedValue.ToString();
// }

你可能感兴趣的:(datagridview)