【发布时间】:2013-06-04 13:36:41
【问题描述】:
我想在 datagridview 中执行一个动作,比如计算。当用户在文本框中输入金额时,我想计算其分期付款。问题是我的datagridview 中还有一个组合框。当我从网格组合框中选择某些内容时,我的代码中出现异常,因此我想在用户单击组合框时停止执行我的计算。
我如何知道用户是否从组合框中单击或选择了某些内容?
private void prol04DataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox tx = e.Control as TextBox;
// Below line i am geting error Because i select combobox in datagrid
DataGridViewTextBoxCell cell = DataGridViewTextBoxCell)prol04DataGridView.CurrentCell;
if (tx != null && cell.OwningColumn == prol04DataGridView.Columns[5])
{
tx.TextChanged -= new EventHandler(tx_TextChanged);
tx.TextChanged += new EventHandler(tx_TextChanged);
}
}
那么我怎样才能找到用户在数据网格上的哪个控件上执行了操作呢?
【问题讨论】:
-
tx == null应该暗示它不是TextBox单元的事实。 -
@Steve 执行是
Unable to cast object of type 'System.Windows.Forms.DataGridViewComboBoxCell' to type 'System.Windows.Forms.DataGridViewTextBoxCell'.
标签: c# winforms visual-studio-2010