Tag Archives: grid

Multiple Cell Selection in DataGridView

9 Sep

DataGridView has a facility to select multiple cells (or a range of cells) using mouse dragging, Cltrl+Click or Shift+Click. This feature is similar to cell selection in spreadsheet applications such as Microsoft Excel.

In order to enable this feature in DataGridView, use ‘SelectionMode’ property as follows:

DataGridViewCell.SelectionMode = DataGridViewSelectionMode.CellSelect;

To read/write data from/to selected cells simply write:

foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
	//read cell data

	//change cell data
	dataGridView1.Rows[cell.RowIndex].Cells[cell.ColumnIndex].Value = 1;
%d bloggers like this: