如何强制DataGridView当前单元格大纲,而不需要按Tab键 [英] How to force DataGridView current cell outline without pressing Tab
问题描述
有没有什么可以这样做的,所以 DataGridView
的当前单元格总是在你所在的标签
按钮?我注意到,如果您已经按下 Tab
按钮,那么当前的单元格总是在其周围有边框,但是我想要在那边开始,而不必按 Tab
按钮。
目前我正在以编程方式发送Tab键,如以下:
SendKeys.Send({TAB});
但是这是kludgy,我宁愿有一个适当的解决方案。 >
编辑:
我忘了提到 SelectionMode
设置为 FullRowSelect
,我不想改变这个。我想要当前单元格的边框轮廓以及整个行被突出显示。
创建一个新的类继承从 DataGridView
并覆盖 ShowFocusCues
属性 - 返回 True
始终显示焦点矩形或 False
至永不显示。您甚至可以添加一个公共属性来暴露它,如果你想要改变它。
public class DataGridViewFocused:DataGridView
{
public bool ShowFocus {get;组; }
protected override bool ShowFocusCues
{
get
{
return this.ShowFocus;
}
}
}
DataGridViewFocusused dataGridView1 = new DataGridViewFocused();
dataGridView1.ShowFocus = true;
注意:这只会关注 CurrentCell
因为这是它的行为。因此,即使设置了 FullRowSelect
,则仅突出显示的一行中所选单元格中的一个将被聚焦。
Is there someway to make it so the current cell of the DataGridView
always has the dashed-line border around it that you get when you press the Tab
button? I've noticed that if you've pressed the Tab
button once after that the current cell always has the border around it, but I'd like to have that border there from the start, without having to press the Tab
button.
Currently I'm programmatically sending the Tab key, as below:
SendKeys.Send("{TAB}");
But this is kludgy and I'd rather have a proper solution if one is available.
Edit:
I forgot to mention that the SelectionMode
is set to FullRowSelect
and I'm not looking to change this. I want the border outline around just the current cell as well as the whole row being highlighted.
Create a new class to inherit from DataGridView
and override the ShowFocusCues
property - returning True
to always show the focus rectangle or False
to never show it. You could even add a public property to expose it if you want to change it on a whim.
public class DataGridViewFocused : DataGridView
{
public bool ShowFocus { get; set; }
protected override bool ShowFocusCues
{
get
{
return this.ShowFocus;
}
}
}
DataGridViewFocused dataGridView1 = new DataGridViewFocused();
dataGridView1.ShowFocus = true;
Note: This will only focus the CurrentCell
as that is just how it behaves. So even with FullRowSelect
set, only one of the selected cells in the highlighted row will be focused.
这篇关于如何强制DataGridView当前单元格大纲,而不需要按Tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!