protected override void OnCellContentClick(DataGridViewCellEventArgs e) { base.OnCellContentClick(e); if (e.RowIndex == -1) { return; } if (SelectedItems == null) { return; } if (DataSource == null || (DataSource is IList) == false) { return; } Object item = ((IList)DataSource)[e.RowIndex]; if (e.ColumnIndex == 0) { var cellValue = this[e.ColumnIndex, e.RowIndex].Value; SelectionChangingEventArgs eArgs = new SelectionChangingEventArgs() { Item = item, IsRemoving = (cellValue != null && (bool)cellValue == true) , RowNumber = e.RowIndex }; this.OnSelectionChanging(eArgs); //if (eArgs.Cancel == true) //{ // this[e.ColumnIndex, e.RowIndex].Value = cellValue; //} } }
protected void OnSelectionChanging(SelectionChangingEventArgs e) { if (SelectionChanging != null) { SelectionChanging(this, e); } if (!e.Cancel) { if (e.IsRemoving) { SelectedItems.Remove(e.Item); } else { SelectedItems.Add(e.Item); } } }
protected override void OnCellContentClick(DataGridViewCellEventArgs e) { base.OnCellContentClick(e); if (e.RowIndex == -1) { return; } if (SelectedItems == null) { return; } if (DataSource == null || (DataSource is IList) == false) { return; } Object item = ((IList)DataSource)[e.RowIndex]; if(e.ColumnIndex == 0) { var cellValue = this[e.ColumnIndex, e.RowIndex].Value; SelectionChangingEventArgs eArgs = new SelectionChangingEventArgs() { Item = item, IsRemoving = (cellValue != null && (bool)cellValue == true) , RowNumber = e.RowIndex }; this.OnSelectionChanging(eArgs); //if (eArgs.Cancel == true) //{ // this[e.ColumnIndex, e.RowIndex].Value = cellValue; //} } }