为datagridview执行输入限制的操作

datagridview是微软在.NET2.0种加入的一个控件,很强大!

在使用中我们经常需要去控制用户在该控件里面的输入,

所以我们需要通过datagridview控件的EditingControlShowing事件来实现对子控件事件的绑定

private void grdFamily2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control is CalendarEditingControl )
            {
                e.Control.Leave += new EventHandler(Control_Leave);
            }
        }

void Control_Leave(object sender, EventArgs e)
        {
            CalendarEditingControl cal = sender as CalendarEditingControl;
            if (CheckBirthDay(Convert.ToDateTime(cal.Text)))
            {
                MessageBox.Show("输入错误!请输入1900年之后的日期!");
                cal.Focus();
            }
        }

 

转载于:https://www.cnblogs.com/EleMMent/archive/2012/12/28/2837080.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值