.NET 4.0和.NET 4.7.2标头选择之间DataGridView的重大更改 [英] Breaking Change in DataGridView between .Net 4.0 and .NET 4.7.2 Header Selection

查看:50
本文介绍了.NET 4.0和.NET 4.7.2标头选择之间DataGridView的重大更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将一个项目从 .NET 4 迁移到了 .NET 4.7.2 ,这在WinForms DataGridView标头中进行了更改.

I recently migrated a Project from .NET 4 to .NET 4.7.2 which introduced a change in the WinForms DataGridView Headers.

预迁移看起来像这样:

Pre Migration looks like this:

如您所见,我当前单击的单元格的标题未被选中.迁移后,相同的DataGridView如下所示:在发行说明

As you can see, the Header of the cell i currently clicked is not selected. After the Migration the same DataGridView looks like this: I could not find any Information mentioning changes in the WinForms DataGridView at the Release Notes

我尝试从此处使用以下代码设置颜色如何更改winform DataGridview标头的颜色?

I tried to set the Color using the following code from here how to change the color of winform DataGridview header?

this.dgvUserFields.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.SystemColors.ControlDark;
this.dgvUserFields.EnableHeadersVisualStyles = false;

但是代码似乎没有任何改变.

But the code does not seem to change anything.

是否有一些资源可以确认这一重大更改,以及如何解决该更改?

Are the some resources confirming that breaking change, and how to fix it ?

推荐答案

该行为记录在

System.Windows.Forms.DataGridView.SelectionMode 设置为 <代码> System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect ,列标题将更改颜色以指示当前列为用户可以在当前行的各个单元格之间进行切换.

When the System.Windows.Forms.DataGridView.SelectionMode is set to System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect, the column header will change color to indicate the current column as the user tabs through the cells in the current row.

在.NET Framework 4.7.2中,当呈现 DataGridViewColumnHeaderCell 时,它将检查列 IsHighlighted ,然后呈现处于推送状态的列,这是要检测的逻辑 IsHighlighted :

In .NET Framework 4.7.2 when rendering DataGridViewColumnHeaderCell, it checks if the column IsHighlighted, then it renders the column in pushed state and here is the logic to detect IsHighlighted:

private bool IsHighlighted()
{
    return this.DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect && 
        this.DataGridView.CurrentCell != null && this.DataGridView.CurrentCell.Selected &&
        this.DataGridView.CurrentCell.OwningColumn == this.OwningColumn &&
        AccessibilityImprovements.Level2;
}

如您在上面的代码中看到的,有&&AccessibilityImprovements.Level2 .这意味着,如果您关闭该功能,则行为将被重置.

As you can see in above code, there is && AccessibilityImprovements.Level2. It means if you turn the feature off, the behavior will be reset.

As also mentioned in the comments by Taw, you can turn the feature off. To do so, you can add this block of setting to app.config file:

<runtime>
    <AppContextSwitchOverrides value="Switch.UseLegacyAccessibilityFeatures=false;Switch.UseLegacyAccessibilityFeatures.2=true" />
</runtime>

这篇关于.NET 4.0和.NET 4.7.2标头选择之间DataGridView的重大更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆