简体   繁体   English

在编辑时捕获DataGridView单元格值

[英]Catch DataGridView Cell value on editing

How can I catch value Cell in DataGridView when user editing this cell? 用户编辑此单元格时如何在DataGridView捕获值Cell?

I would validate on "real-time" input text. 我会验证“实时”输入文本。

You can use CellEndEdit event for DataGridView . 您可以将CellEndEdit事件用于DataGridView

添加CellEndEdit事件

Then you can access cell value using following code 然后,您可以使用以下代码访问单元格值

((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value

I just displayed data in the cell in messagebox. 我只是在消息框中的单元格中显示了数据。 Code will look like: 代码如下所示:

 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        MessageBox.Show(((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM