private void GridViewClickHandler(object sender, DataGridViewCellEventArgs e) { JcwDataGridView gridView = sender as JcwDataGridView; if (gridView != null && gridView.CurrentRow != null) { // Validate that the row being edited in fact can be edited by checking the CanIncludeInAggregate property on the data bound object. ChartStatistic statistic = gridView.CurrentRow.DataBoundItem as ChartStatistic; if (statistic != null) { if (statistic.CanIncludeInAggregate) { // If the current cell is the include column cell, raise the recalculate aggregate event. if (gridView.CurrentCell.ColumnIndex.Equals(IncludeColumn.Index)) { if (OnRecalculateAggregate != null) { OnRecalculateAggregate(this, EventArgs.Empty); } } } else { gridView.CancelEdit(); } } } }
private void GridView_CurrentCellDirtyStateChanged(object sender, EventArgs e) { JcwDataGridView gridView = sender as JcwDataGridView; if (gridView != null) { // Validate that the row being edited in fact can be edited by checking the CanIncludeInAggregate property on the data bound object. ChartStatistic statistic = gridView.CurrentRow.DataBoundItem as ChartStatistic; if (statistic != null) { if (statistic.CanIncludeInAggregate) { // Commit the change when a checkbox cell is clicked so that by the time we get into the CellContentClick // handler the cells value has already been updated. if (gridView.CurrentCell is DataGridViewCheckBoxCell) { gridView.CommitEdit(DataGridViewDataErrorContexts.Commit); } } } } }