Disabling Highlighting on a ListView

Connor Frayne 25 Reputation points
2024-07-10T19:17:32.4133333+00:00

Hello,
I'm making a program to display a GUI with multiple icons showing the state of devices connected to a master device, so far It's going great except the Item I used to store them in, ListView, has an issue, When selected the icon and text highlights in blue. Are there any way to disable the highlighting without disabling the functionality to select the icons.

Thank you,

Connor Frayne

User's image

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,189 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,735 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,216 Reputation points Microsoft Vendor
    2024-07-11T03:20:30.2933333+00:00

    Hi @Connor Frayne ,

    You can set the OwnerDraw property of the ListView to True. Then handle the DrawItem event to custom draw the items.

    Private Sub ListView1_DrawItem(sender As Object, e As DrawListViewItemEventArgs) Handles ListView1.DrawItem
        If e.Item.Selected Then
            e.Graphics.FillRectangle(Brushes.White, e.Bounds)
        Else
            e.DrawBackground()
        End If
        
        e.Graphics.DrawString(e.Item.Text, e.Item.Font, Brushes.Black, e.Bounds.Left, e.Bounds.Top)
        
        If e.Item.ImageIndex >= 0 Then
            Dim img As Image = ListView1.LargeImageList.Images(e.Item.ImageIndex)
            e.Graphics.DrawImage(img, e.Bounds.Left, e.Bounds.Top)
        End If
    End Sub
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.