日期:2014-05-20  浏览次数:20850 次

DataGridView.CellValidating 事件的问题
我调协了这个事件,我是用手去邦定数据

邦定数据的时候就报错了,好像就在执行这个事件

不知道怎么解决?


private   void   dataGridView1_CellValidating(object   sender,
        DataGridViewCellValidatingEventArgs   e)
{
        dataGridView1.Rows[e.RowIndex].ErrorText   =   " ";
        int   newInteger;

        //   Don 't   try   to   validate   the   'new   row '   until   finished  
        //   editing   since   there
        //   is   not   any   point   in   validating   its   initial   value.
        if   (dataGridView1.Rows[e.RowIndex].IsNewRow)   {   return;   }
        if   (!int.TryParse(e.FormattedValue.ToString(),
                out   newInteger)   ||   newInteger   <   0)
        {
                e.Cancel   =   true;
                dataGridView1.Rows[e.RowIndex].ErrorText   =   "the   value   must   be   a   non-negative   integer ";
        }
}


------解决方案--------------------
使用CellValidated呢?
------解决方案--------------------
细看:不可能啊!出什么错?

-----------------
我手动绑定不会出错!