Beispiel #1
0
        /// ------------------------------------------------------------------------------------
        private void HandleGridRowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (e.RowIndex == _grid.RowCount - 1 || !_grid.IsCurrentRowDirty)
            {
                return;
            }

            _grid.IsDirty = true;

            var contribution = GetContributionFromRow(e.RowIndex);

            if (ValidatingContributor == null)
            {
                return;
            }

            var args = new CancelEventArgs(e.Cancel);
            var kvp  = ValidatingContributor(this, contribution, args);

            e.Cancel = args.Cancel;

            if (!string.IsNullOrEmpty(kvp.Key))
            {
                if (_msgWindow == null)
                {
                    _msgWindow = new FadingMessageWindow();
                }

                var dataGridViewColumn = _grid.Columns[kvp.Key];
                if (dataGridViewColumn != null)
                {
                    int col = dataGridViewColumn.Index;
                    var rc  = _grid.GetCellDisplayRectangle(col, e.RowIndex, true);
                    var pt  = new Point(rc.X + (rc.Width / 2), rc.Y + 4);
                    _msgWindow.Show(kvp.Value, _grid.PointToScreen(pt));

                    // Invoking here because of "reentrant call to the SetCurrentCellAddressCore" exception.
                    // Setting the CurrentCell can trigger validation again.
                    BeginInvoke((Action)(() => _grid.CurrentCell = _grid[col, e.RowIndex]));
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        private void HandleGridRowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (e.RowIndex == _grid.RowCount - 1 || !_grid.IsCurrentRowDirty)
            {
                return;
            }

            _grid.IsDirty = true;

            var contribution = GetContributionFromRow(e.RowIndex);

            if (ValidatingContributor == null)
            {
                return;
            }

            var args = new CancelEventArgs(e.Cancel);
            var kvp  = ValidatingContributor(this, contribution, args);

            e.Cancel = args.Cancel;

            if (!string.IsNullOrEmpty(kvp.Key))
            {
                if (_msgWindow == null)
                {
                    _msgWindow = new FadingMessageWindow();
                }

                var dataGridViewColumn = _grid.Columns[kvp.Key];
                if (dataGridViewColumn != null)
                {
                    int col = dataGridViewColumn.Index;
                    var rc  = _grid.GetCellDisplayRectangle(col, e.RowIndex, true);
                    var pt  = new Point(rc.X + (rc.Width / 2), rc.Y + 4);
                    _msgWindow.Show(kvp.Value, _grid.PointToScreen(pt));
                    _grid.CurrentCell = _grid[col, e.RowIndex];
                }
            }
        }