如何禁用在DataGridView中选择的能力? [英] How to disable the ability to select in a DataGridView?

查看:89
本文介绍了如何禁用在DataGridView中选择的能力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想使用我的 DataGridView 来显示内容,而我希望用户不能从<$ c $中选择任何行,字段或任何内容c> 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.

我该怎么做?

推荐答案

我会一起去:

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

我不同意广泛的断言,没有 DataGridView 应该是不可选的。一些UI是为工具或触屏创建的,并允许选择误导用户认为选择实际上会使他们在某个地方。

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.

在控件上设置 ReadOnly = true 对单元格或行是否可以选择没有影响。而且设置 Enabled = false 的视觉和功能缺点

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.

这篇关于如何禁用在DataGridView中选择的能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆