如何接受datagrid单元格中的数值 [英] How to accept numeric values in datagrid cell

查看:70
本文介绍了如何接受datagrid单元格中的数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



datagridcell只接受我在dgv_CellValidating下编写此代码的数字值,但它不能正常运行哪个事件

Hi
datagridcell Accept only numeric values i wrote this code under dgv_CellValidating,but its not working which event is currect

if (e.ColumnIndex == 4) // 1 should be your column index
{
    int i;

    if (!int.TryParse(Convert.ToString(e.FormattedValue), out i))
    {
        e.Cancel = true;
        label1.Text = "please enter numeric";
    }
    else
    {
        // the input is numeric
    }
}

推荐答案

仅在列中写数字

使用tb_keypress和dgv_EditingControlShowing事件

例如...

http://www.daniweb.com/software-development/csharp/threads/226941/enter-only -number-in-datagridview [ ^ ]

快乐编码!

:)
to write numbers only in column
use tb_keypress and dgv_EditingControlShowing event
for example...
http://www.daniweb.com/software-development/csharp/threads/226941/enter-only-number-in-datagridview[^]
Happy coding!
:)


你好,



这就在MSDN文档中。请查看MSDN上的链接如何使用CellValidating事件完成。



问候,
Hello,

This is right there in MSDN documentation. Please have a look at this link on MSDN, which show how it can be done using CellValidating event.

Regards,


这篇关于如何接受datagrid单元格中的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆