Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the ability to select in a DataGridView?

I want to use my DataGridView only to show things, and I want the user not to be able to select any row, field or anything from the DataGridView.

How can I do this?

like image 543
Mahdi Tahsildari Avatar asked Jul 04 '12 13:07

Mahdi Tahsildari


People also ask

How to disable selection in DataGridView?

Some UIs are built for tools or touchsreens, and allowing a selection misleads the user to think that selecting will actually get them somewhere. Setting ReadOnly = true on the control has no impact on whether a cell or row can be selected. And there are visual and functional downsides to setting Enabled = false .

How do I make datagrid read only?

You can make entire dataGridView or entire column or entire row as ReadOnly . dataGridView1. ReadOnly = true; dataGridView1.

What is DataGridView control?

The DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the DataGridView control to show read-only views of a small amount of data, or you can scale it to show editable views of very large sets of data.

Which is a property of the DataGridView control?

The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.


1 Answers

I'd go with this:

private void myDataGridView_SelectionChanged(Object sender, EventArgs e) {     dgvSomeDataGridView.ClearSelection();   } 

I don't agree with the broad assertion that no DataGridView should be unselectable. Some UIs are built for tools or touchsreens, and allowing a selection misleads the user to think that selecting will actually get them somewhere.

Setting ReadOnly = true on the control has no impact on whether a cell or row can be selected. And there are visual and functional downsides to setting Enabled = false.

Another option is to set the control selected colors to be exactly what the non-selected colors are, but if you happen to be manipulating the back color of the cell, then this method yields some nasty results as well.

like image 95
edhubbell Avatar answered Oct 13 '22 08:10

edhubbell