public void DataGridViewSelectedRowCollection_CopyTo_InvokeEmpty_Success() { using var control = new DataGridView(); DataGridViewSelectedRowCollection collection = control.SelectedRows; var array = new object[] { 1, 2, 3 }; collection.CopyTo(array, 1); Assert.Equal(new object[] { 1, 2, 3 }, array); }
public void DataGridViewSelectedRowCollection_CopyTo_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; var array = new object[] { 1, 2, 3 }; collection.CopyTo(array, 1); Assert.Equal(new object[] { 1, control.Rows[2], control.Rows[0] }, array); }
private void dgvContent_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex == -1) { DataGridViewRow[] copy = new DataGridViewRow[this.dgvContent.SelectedRows.Count]; DataGridViewSelectedRowCollection collection = this.dgvContent.SelectedRows; collection.CopyTo(copy, 0); this.dgvContent.ClearSelection(); foreach (DataGridViewRow row in this.dgvContent.Rows) { if (row.Index == -1) { continue; } row.Cells[0].Value = (!this._checkAllStatus).ToString(); } this._checkAllStatus = !this._checkAllStatus; if (this._checkAllStatus == true) { this.tsbRemoveSelectedContent.Enabled = true; } else { this.tsbRemoveSelectedContent.Enabled = false; } this.dgvContent.EndEdit(); foreach (DataGridViewRow row in copy) { row.Selected = true; } this.dgvContent.Update(); } }