我在一个模态窗口中有一个DataGridView,其中包含我的程序选项列表。网格有两个柱子。第一个包含用于选择该选项的复选框,seccond是该选项的名称/描述。 winform还包含确定和取消按钮,但这不是重点。下面的代码完成了我想要的。由于FullRowSelect属性,选中/取消选中该复选框,您可以单击该行的任何位置。但它不再显示当前行周围的蓝色背景或虚线。如何在不丢失任何当前功能的情况下添加它?
编辑: 详细说明;我想要的是再次启用所选行/单元格上的虚线和/或蓝色背景。它看起来像我目前以某种方式禁用此代码......
相关的当前代码:
public OptionsForm()
{
InitializeComponent();
OptionsRoot = Options.GetReadOnlyRoot(OptionsBannersNameValueList.GetNameValueList(Settings.Default.OptionsBanners));
optionsBannersDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
optionsBannersDataGridView.MultiSelect = false;
optionsBannersDataGridView.RowPrePaint += new DataGridViewRowPrePaintEventHandler(optionsBannersDataGridView_RowPrePaint);
InitUI();
Closing += MyFormClosing;
BindingSourceTree = BindingSourceHelper.InitializeBindingSourceTree(components, rootBindingSource);
}
private void optionsBannersDataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
e.PaintParts &= ~DataGridViewPaintParts.Focus;
}
答案 0 :(得分:2)
我会尝试使用.OnCellClick
方法并将行颜色设置为蓝色。我认为你也应该能够添加虚线边框。
我相信你可以这样称呼它:
optionsBannersDataGridView.OnCellClick += new DataGridViewCellEventArgs(optionsBannersDataGridView_OnCellClick);
答案 1 :(得分:0)
我最终完成的工作是删除上面提到的大部分代码,因为它确实没有做太多。出于某种原因,当我在visual studio中设置属性时,它不起作用,但现在确实如此。我不知道那里发生了什么,但那不是重点。
构造函数现在看起来像这样:
public OptionsForm()
{
InitializeComponent();
AlternativerRoot = Alternativer.GetReadOnlyRoot(AlternativerFanerNameValueList.GetNameValueList(Settings.Default.AlternativerFaner));
InitUI();
Closing += MyFormClosing;
_bindingSourceTree = BindingSourceHelper.InitializeBindingSourceTree(components, rootBindingSource);
}
属性在visual studio GUI中设置。 SelectionMode设置为FullRowSelect,MultiSelect设置为false。
我仍然没有得到我想要的焦点所以我在Visual Studio中将所选行的背景颜色设置为蓝色,将前景颜色设置为白色。现在这就像我想要的那样。
我仍然不知道为什么之前没有正确设置属性,但至少现在可以正常工作:P