2009-04-30 118 views
0

我有一个模式窗口中的DataGridView和我的程序的选项列表。网格有两个柱子。第一个包含用于选择该选项的复选框,第二个是该选项的名称/描述。该winform还包含确定和取消按钮,但这是重点。下面的代码做我想要的。由于FullRowSelect属性的复选框被选中/未选中,因此您可以在该行中单击任意位置。但它不会在当前行周围显示蓝色背景或虚线。我将如何在不失去任何当前功能的情况下添加此功能?DataGridView: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

我终于ened了做是去除大部分上述代码的,因为它确实没有做太多。由于某些原因,当我在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。

我仍然没有得到我想要的焦点,所以我将所选行的背景颜色设置为蓝色,并在视觉工作室中将前景色设置为白色。这现在就像我想要的那样工作。

我仍然不知道为什么性能没得到正确设置较早,但至少现在的工作:P

2

我会尝试使用.OnCellClick方法和行颜色设置为蓝色。我认为你应该也可以添加一个虚线边框。

我相信你可以这样调用:

optionsBannersDataGridView.OnCellClick += new DataGridViewCellEventArgs(optionsBannersDataGridView_OnCellClick); 
+0

这会确保最上面一行是加载时的蓝色,但? – Sakkle 2009-04-30 09:37:56