为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();
            }
        }

 

posted @ 2012-12-28 11:45  EleMMent  阅读(364)  评论(0编辑  收藏  举报