SharpDataGridView OnDataError

  protected override void OnDataError(bool displayErrorDialogIfNoHandler, DataGridViewDataErrorEventArgs e)
        {
            if ((e.Exception) is ConstraintException)
            {
                //DataGridView view = (DataGridView)sender;
                this.Rows[e.RowIndex].ErrorText = e.Exception.Message;
                e.Cancel = true;
                e.ThrowException = false;
                //displayErrorDialogIfNoHandler = false;
            }
            base.OnDataError(displayErrorDialogIfNoHandler, e);
            //MessageBox.Show("Error happened " + e.Context.ToString());

            //if (e.Context == DataGridViewDataErrorContexts.Commit)
            //{
            //    MessageBox.Show("Commit error");
            //}
            //if (e.Context == DataGridViewDataErrorContexts.CurrentCellChange)
            //{
            //    MessageBox.Show("Cell change");
            //}
            //if (e.Context == DataGridViewDataErrorContexts.Parsing)
            //{
            //    MessageBox.Show("parsing error");
            //}
            //if (e.Context == DataGridViewDataErrorContexts.LeaveControl)
            //{
            //    MessageBox.Show("leave control error");
            //}

            //if ((e.Exception) is ConstraintException)
            //{
            //    //DataGridView view = (DataGridView)sender;
            //    this.Rows[e.RowIndex].ErrorText = "an error";
            //    this.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "an error";

            //    e.ThrowException = false;
            //}

        }

posted @ 2010-08-30 22:06  leslie116  阅读(278)  评论(0编辑  收藏  举报