首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在datagridview中单击哪个控件

在datagridview中单击哪个控件
EN

Stack Overflow用户
提问于 2013-06-04 21:36:42
回答 1查看 185关注 0票数 0

我想在datagridview中执行一个操作,比如计算。当用户在文本框中输入金额时,我想要计算其分期付款。问题是我的datagridview中也有一个combobox。当我从网格组合框中选择一些东西时,我的代码中出现异常,所以我想在用户单击组合框时停止执行我的计算。

我如何知道用户是否从combobox中单击或选择了某项内容?

代码语言:javascript
运行
复制
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);
     }             
}

那么,我如何找到用户在datagrid上的哪个控件上执行了操作呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-04 21:40:42

将用于将e.Control转换为TextBox的相同逻辑也应用于CurrentCell

代码语言:javascript
运行
复制
 TextBox tx = e.Control as TextBox;
 DataGridViewTextBoxCell cell = prol04DataGridView.CurrentCell as DataGridViewTextBoxCell;
 if (tx != null && cell != null && cell.OwningColumn == prol04DataGridView.Columns[5])
 {
       tx.TextChanged -= new EventHandler(tx_TextChanged);
       tx.TextChanged += new EventHandler(tx_TextChanged);

 }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16919376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档