WinForms ListView.HideSelection 属性没有效果?

发布于 2024-09-24 22:14:32 字数 529 浏览 2 评论 0原文

我正在开发一个应用程序,其中使用列表视图来选择要显示的数据集。当用户单击列表项时,主视图将使用与所选项目关联的数据进行更新,并且 ListView 控件将失去焦点。失去焦点后,即使我已明确将 HideSelection 设置为 false,控件也会停止突出显示所选项目。

根据 MSDN “如果控件失去焦点时所选项目不突出显示,则为 true;如果控件失去焦点时所选项目仍然突出显示,则为 false。默认值为 true。”

这是一个错误吗?我错过了什么吗?我们正在使用 .NET 2.0 版本。 (是的,我已经检查过该属性没有在设计器生成的代码之外的任何地方设置)


编辑:显然,选择被突出显示了,尽管非常微妙。查看属性列表后,我没有找到在控件没有焦点时更改突出显示颜色的方法。有什么想法吗?谢谢。

I'm working on an application in which a list view is used to select what set of data to display. When the user clicks a list item, the main view updates with the data associated with the selected item, and the ListView control loses focus. Upon losing focus, the control stops highlighting the selected item even though I've explicitly set HideSelection to false.

According to MSDN:
"true if the selected item does not appear highlighted when the control loses focus; false if the selected item still appears highlighted when the control loses focus. The default is true."

Is this a bug, or am I missing something? We are using .NET version 2.0. (Yes, I've checked that the property isn't set anywhere outside of the designer-generated code)


Edit: Apparently the selection was highlighted, albeit very subtly. After looking through the list of properties I don't see a way to change the highlighting color when the control doesn't have focus. Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请别遗忘我 2024-10-01 22:14:32

你确定这不仅仅是真的很难看到吗?在我的屏幕上,区别是白色与“非常非常淡的灰色”——非常微妙。如果您在调查时更改 ListView 的背景颜色(另外,尝试调低 VDU 亮度),情况会更明显。

如下所示;实际上选择了“def”。

不,确实是

Are you sure it isn't just really, really hard to see. On my screen the difference is white vs "really really pale grey" - very subtle. It is more obvious if you change the ListView's background colour while you investigate (also, try turning down your VDU brightness).

Shown below; the "def" is actually selected.

No, really it is

甚是思念 2024-10-01 22:14:32

某些液晶显示器确实存在显示灰色颜色不够鲜明的问题。它是一个系统设置,会影响所有程序,您不能仅更改您自己的程序。考虑到这确实是您的显示器的问题,没有理由不通过更改系统颜色来解决它。

使用控制面板 + 显示屏。在 Win7 上,单击个性化、窗口颜色、高级外观设置。在对话框中选择“禁用项目”。

Some LCD monitors do indeed have a problem showing the gray color distinctive enough. It is a system setting and affects all programs, you cannot change it for just your own. Given that this really a problem with your monitor, there's little reason to not just fix it by changing the system color.

Use Control Panel + Display. On Win7 click Personalization, Window Color, Advanced Appearance Settings. Select "Disabled Item" in the dialog.

守不住的情 2024-10-01 22:14:32

我不知道这是否有帮助,但这就是我在 C# 中必须做的

  private void Form1_Load(object sender, EventArgs e)
    {            
    listView1.HideSelection = true;
    listView1.FullRowSelect = false;
    };
           

 private void ListView_SelectedIndexChanged(object sender, EventArgs e)
    {
        System.Windows.Forms.ListView listView = sender as System.Windows.Forms.ListView; // Fully qualify if needed
        if (listView != null)
        {
            // Reset colors of all items
            foreach (System.Windows.Forms.ListViewItem item in listView.Items) // Fully qualify if needed
            {
                item.BackColor = listView.BackColor;
                item.ForeColor = listView.ForeColor;
            }

            // Highlight the selected item
            if (listView.SelectedItems.Count > 0)
            {
                foreach (System.Windows.Forms.ListViewItem selectedItem in listView.SelectedItems) // Fully qualify if needed
                {
                    selectedItem.BackColor = System.Drawing.Color.LightBlue; // Highlight color
                    selectedItem.ForeColor = System.Drawing.Color.Black; // Text color
                }
            }
        }
    }

I dont know if this would help but this is what I had to do in C#

  private void Form1_Load(object sender, EventArgs e)
    {            
    listView1.HideSelection = true;
    listView1.FullRowSelect = false;
    };
           

 private void ListView_SelectedIndexChanged(object sender, EventArgs e)
    {
        System.Windows.Forms.ListView listView = sender as System.Windows.Forms.ListView; // Fully qualify if needed
        if (listView != null)
        {
            // Reset colors of all items
            foreach (System.Windows.Forms.ListViewItem item in listView.Items) // Fully qualify if needed
            {
                item.BackColor = listView.BackColor;
                item.ForeColor = listView.ForeColor;
            }

            // Highlight the selected item
            if (listView.SelectedItems.Count > 0)
            {
                foreach (System.Windows.Forms.ListViewItem selectedItem in listView.SelectedItems) // Fully qualify if needed
                {
                    selectedItem.BackColor = System.Drawing.Color.LightBlue; // Highlight color
                    selectedItem.ForeColor = System.Drawing.Color.Black; // Text color
                }
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文