之前想使用DataGridView的SelectionChanged事件,但是使用了后并没有达到效果
最后使用下面的方式实现:
private void materialCheckGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { int cidx = materialCheckGridView.CurrentCell.ColumnIndex; if (materialCheckGridView.Columns[cidx].Name == "ColRetMainDefect") { //还原控件并绑定事件 ((ComboBox)e.Control).SelectedIndexChanged += new EventHandler(MaterialCheckForm_SelectedIndexChanged); } } private void MaterialCheckForm_SelectedIndexChanged(object sender, EventArgs e) { int cindex = materialCheckGridView.CurrentRow.Index; if (cindex >= 0) { int idx = materialCheckGridView.CurrentCell.ColumnIndex; if (materialCheckGridView.Columns[idx].HeaderText == "回修主要病疵") { //int cindex = materialCheckGridView.CurrentCell.RowIndex; string defdesc = ProdReportDA.GetDefectsDescription(materialCheckGridView.Rows[cindex].Cells["ColRetMainDefect"].EditedFormattedValue.ToString(), materialCheckGridView.Rows[cindex].Cells["RollId"].Value.ToString()); materialCheckGridView.Rows[cindex].Cells["ColDefectDesc"].Value = defdesc; } } }
原文地址:https://www.cnblogs.com/hubbert123/p/10334117.html
时间: 2024-11-01 14:50:31