总共有三个事件
DgvFeeInspection_CellClick事件
DgvFeeInspection_EditingControlShowing事件
editingControl_TextChanged自定义事件
static bool bo = false;
private void DgvFeeInspection_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (DgvFeeInspection.Rows.Count >= 1)
{
try
{
if (this.DgvFeeInspection.CurrentCell.ColumnIndex != 4)
bo = false;
else
bo = true;
}
catch
{ }
}
}
private void DgvFeeInspection_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (DgvFeeInspection.Rows.Count >= 1)
{
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);
}
}
}
private void editingControl_TextChanged(object sender, EventArgs e)
{
if (DgvFeeInspection.Rows.Count >= 1)
{
if (bo == true)
{
string str = DgvFeeInspection.CurrentCell.EditedFormattedValue.ToString();
SpellAndWbCode spell = new SpellAndWbCode();
this.DgvFeeInspection.Rows[DgvFeeInspection.CurrentCell.RowIndex].Cells["Column1"].Value = spell.GetSpellCode(str);
this.DgvFeeInspection.Rows[DgvFeeInspection.CurrentCell.RowIndex].Cells["Column1"].ReadOnly = true;
}
}
}