user1532468
user1532468

Reputation: 1753

Disable click in DataGridvIew

I have a DataGridView 'DGV' that is set to readonly via the properties panel. My question is, why if the DGV is set to readonly, users are able to click within the grid? I thought that by setting a grid to readonly, it removed this function.

I have tried various ways to disable any clicks in the grid but no luck. Can anyone shed some light on how to make the grid strictly read only with no user interaction allowed. Thanks

Things I have tried at both after the grid has loaded and before.

DGV.ReadOnly = True
DGV.ClearSelection()

Upvotes: 1

Views: 7073

Answers (2)

Vland
Vland

Reputation: 4262

ReadOnly property has nothing to do with the possibility of clicking it. It just means that you can't edit its cells.

I suggest disabling the selection completely handling the SelectionChanged event

Private Sub DataGridView1_SelectionChanged(sender As System.Object, e As System.EventArgs) Handles DataGridView1.SelectionChanged
    DataGridView1.ClearSelection()
End Sub

and also setting the DataGridView1.RowHeadersVisible = False

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    DataGridView1.RowHeadersVisible = False
End Sub

Upvotes: 1

Fabio
Fabio

Reputation: 32445

Set
datagridview.DefaultCellStyle.SelectionBackColor to same value as .BackColor
and datagridview.DefaultCellStyle.SelectionForeColor to same value as .ForeColor

Then user cannot notice if it was clicked...

Upvotes: 2

Related Questions