0

我在模式窗口中有一个 DataGridView,其中包含我的程序的选项列表。网格有两个列。第一个包含用于选择该选项的复选框,第二个是该选项的名称/描述。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;
}
4

2 回答 2

2

我会尝试使用该.OnCellClick方法并将行颜色设置为蓝色。我认为您也应该能够添加虚线边框。

我相信你可以这样称呼它:

optionsBannersDataGridView.OnCellClick += new DataGridViewCellEventArgs(optionsBannersDataGridView_OnCellClick);
于 2009-04-30T08:54:42.083 回答
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

于 2009-05-05T11:42:03.073 回答