vb.net 在 DataGridvView 中禁用单击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20969330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable click in DataGridvIew
提问by user1532468
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.
我有一个 DataGridView 'DGV',它通过属性面板设置为只读。我的问题是,为什么如果 DGV 设置为只读,用户可以在网格内单击?我认为通过将网格设置为只读,它删除了这个功能。
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()
采纳答案by Vland
ReadOnly property has nothing to do with the possibility of clicking it. It just means that you can't edit its cells.
ReadOnly 属性与单击它的可能性无关。这只是意味着您无法编辑其单元格。
I suggest disabling the selection completely handling the SelectionChangedevent
我建议禁用选择完全处理SelectionChanged事件
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
并且还设置 DataGridView1.RowHeadersVisible = False
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DataGridView1.RowHeadersVisible = False
End Sub
回答by Fabio
Setdatagridview.DefaultCellStyle.SelectionBackColorto same value as .BackColor
and datagridview.DefaultCellStyle.SelectionForeColorto same value as .ForeColor
设置datagridview.DefaultCellStyle.SelectionBackColor为相同的值.BackColor
和datagridview.DefaultCellStyle.SelectionForeColor相同的值.ForeColor
Then user cannot notice if it was clicked...
然后用户无法注意到它是否被点击......

