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?
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 .
You can make entire dataGridView or entire column or entire row as ReadOnly . dataGridView1. ReadOnly = true; dataGridView1.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With