- dataGridView添加EditingControlShowing事件
private void gridSetup_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
if (gridSetup.CurrentCell.OwningColumn.Name == "clmSetupStation")
{
//添加TextChanged事件而非SelectedIndexChanged
((ComboBox)e.Control).TextChanged += WorkorderSetupForm_TextChanged;
}
}
catch (Exception ex)
{
LogHelper.Error(ex.Message + ";" + ex.StackTrace);
SetStatusLabelText("Remove setup fail", 1);
}
}
- WorkorderSetupForm_TextChanged
private void WorkorderSetupForm_TextChanged(object sender, EventArgs e)
{
try
{
ComboBox combox = sender as ComboBox;
if (combox == null)
{
return;
}
//MLManager mLHanlder = new MLManager(sessionContext, initModel, this.view);
DataGridViewRow row = gridSetup.CurrentRow;
//点击目标单元格时可能会触发不需要的事件,需要过滤掉
if (string.IsNullOrEmpty(station) || station == "System.Data.DataRowView")
{
return;
}
if (station == row.Cells["clmSetupStation"].Value.ToString())
{
return;
}
row.Cells["clmSetupStation"].Value = station;
((DataGridViewImageCell)row.Cells["clmSetupStaus"]).Value = squareFillCloseImage;
row.Cells["clmSetupMaterialBinNumber"].Value = "";
}
catch (Exception ex)
{
LogHelper.Error(ex.Message + ";" + ex.StackTrace);
}
}