Hide selection highlight on click and mouseover in radListView?

1 Answer 53 Views
ListView
Willy
Top achievements
Rank 2
Iron
Iron
Willy asked on 01 Mar 2022, 08:17 PM | edited on 01 Mar 2022, 08:18 PM

Hello, 

My question is: How can I hide the on hover highlighting and also when the user clicks on an item highlighting? I just want a flat color with no highlighting on hover and on clicking? I have tried the .ListViewElement.ViewElement.HighlightColor but that doesn't seem to work. 

Thank you for helping. 

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Mar 2022, 09:35 AM
Hello, Bill,

According to the provided screenshot, I suspect that you are using the CrystalDark theme in your project. Please correct me if I am wrong. 

The easiest way to disable any highlight or selected style is to customize the theme in Visual Style Builder for the respective elements states. A sample approach how a theme can be customized is demonstrated in the following article:
https://docs.telerik.com/devtools/winforms/knowledge-base/customize-a-theme 

An alternative solution that I can suggest is to handle the VisualItemFormatting event and apply the flat color you want to the visual items: 
        private void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
        {
            e.VisualItem.DrawBorder = false;
            e.VisualItem.DrawFill = true;
            e.VisualItem.GradientStyle = GradientStyles.Solid;
            e.VisualItem.BackColor = this.radListView1.ListViewElement.BackColor;
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Willy
Top achievements
Rank 2
Iron
Iron
commented on 03 Mar 2022, 04:35 PM

Thank you that solves my problem.
Willy
Top achievements
Rank 2
Iron
Iron
commented on 04 Mar 2022, 10:11 PM

Quick question...how do I change the selection highlight backcolor and forecolor?
Dess | Tech Support Engineer, Principal
Telerik team
commented on 07 Mar 2022, 07:55 AM

Hi, Bill,

You can extend the previous code snippet and include changing the ForeColor when the item is selected:

        public RadForm1()
        {
            InitializeComponent();

        this.radListView1.VisualItemFormatting+=radListView1_VisualItemFormatting;
        }

        private void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
        {
            e.VisualItem.DrawBorder = false;
            e.VisualItem.DrawFill = true;
            e.VisualItem.GradientStyle = GradientStyles.Solid;
            e.VisualItem.BackColor = this.radListView1.ListViewElement.BackColor;

            if (e.VisualItem.Data.Selected)
            {
                e.VisualItem.ForeColor = Color.Red;
            }
            else
            {
                e.VisualItem.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }

The same approach can be followed with the BackColor as well. By using this event to customize the items appearance, you should always provide an else clause, where you reset the appearance settings which you have introduced. This is necessary since RadListView uses data virtualization, which might lead to unpredicted appearance results when items are being reused:

https://docs.telerik.com/devtools/winforms/controls/listview/customizing-appearance/formatting-items 

Tags
ListView
Asked by
Willy
Top achievements
Rank 2
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or