如何禁用一个DataGridView选择的能力?能力、DataGridView

2023-09-03 04:42:15 作者:为爱而醉

我想用我的的DataGridView 只显示的东西,我希望用户不能够从的DataGridView 。

我怎样才能做到这一点?

解决方案

我会用这个去:

 私人无效dgvSomeDataGridView_SelectionChanged(对象发件人,EventArgs的)
{
    dgvSomeDataGridView.ClearSelection()
}
 

我不与广泛的说法一致认为,没有的DataGridView 应该是不可选择的。一些用户界面是专为工具或touchsreens,并允许选择误导用户认为,选择将真正得到他们的地方。

设置只读=真正的上的控制对一个单元格或行是否可以选择没有影响。并且有视觉和功能缺点制定已启用=假

另一种选择是在控制设置选择的颜色是什么非选择颜色,但如果碰巧被操纵电池的背面的颜色,则此方法产生一些讨厌结果,以及

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.

c winform 怎么将datagridview中的选中多行的数据保存到一个 .txt文件中

How can I do this?

解决方案

I'd go with this:

private void dgvSomeDataGridView_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.