public void DataGridViewSelectedRowCollection_Contains_InvokeEmpty_ReturnsFalse(DataGridViewRow dataGridViewRow) { using var control = new DataGridView(); DataGridViewSelectedRowCollection collection = control.SelectedRows; Assert.False(collection.Contains(dataGridViewRow)); }
public void DataGridViewSelectedRowCollection_Contains_InvokeNotEmpty_ReturnsExpected() { using var control = new DataGridView { ColumnCount = 1, RowCount = 3 }; control.Rows[0].Selected = true; control.Rows[1].Selected = false; control.Rows[2].Selected = true; DataGridViewSelectedRowCollection collection = control.SelectedRows; Assert.True(collection.Contains(control.Rows[0])); Assert.False(collection.Contains(control.Rows[1])); Assert.True(collection.Contains(control.Rows[2])); Assert.False(collection.Contains(new DataGridViewRow())); Assert.False(collection.Contains(null)); }
private void grid_CurrentCellDirtyStateChanged(object sender, EventArgs e) { var grid = sender as DataGridView; if (grid.IsCurrentCellDirty) { if (grid.CurrentCell is DataGridViewTextBoxCell) { return; } grid.CommitEdit(DataGridViewDataErrorContexts.Commit); grid.CancelEdit(); } if (grid.CurrentCell != null && _selectedRows != null && grid.CurrentCell.OwningColumn is DataGridViewCheckBoxColumn) { var selectedValue = (bool)grid.CurrentCell.Value; foreach (var row in grid.Rows.OfType <DataGridViewRow>()) { if (_selectedRows.Contains(row)) { if (row.Index == grid.CurrentCell.RowIndex) { continue; } row.Cells[grid.CurrentCell.OwningColumn.Name].Value = selectedValue; row.Selected = true; } else { row.Selected = false; } } } _selectedRows = null; }