Results 1 to 4 of 4

Thread: Don't turn SelectedListviewItem gray when losing focus

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Talking Don't turn SelectedListviewItem gray when losing focus

    Hi!

    If someone is still wondering (and I didn't find one satisfying answer anywhere and setting hideselection=false also didn't work ):

    If you don't want your listview to turn the background color of a selected listviewitem to gray when the listview loses focus, then put this into your subclassed listview:

    VB Code:
    1. Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
    2.         If Not m.Msg = 8 Then MyBase.DefWndProc(m)
    3.     End Sub

    As I figure, this traps the message that is responsible for it.

    Although I really don't know why it is so difficult to find a list of all the messages (and their relating codes) on the net (and I didn't find that one, too)

    Anyhow, that works for me now

    Regards!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Don't turn SelectedListviewItem gray when losing focus

    wouldn't it be hideselection=true for what you wanted to do?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Don't turn SelectedListviewItem gray when losing focus

    Yes, it would work but if you wanted the selection to remain then it wont. Isnt there a Ghosted property that
    you can set the color of and maybe duplicate the selected color.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: Don't turn SelectedListviewItem gray when losing focus

    If I turn hideselection=true then the highlighted item turns white when losing focus and you don't see it anymore. When hideselection=false then it just turns to gray.

    Also, I didn't find a way to set the background color of a selected item without making item.selected=false because otherwise some mechanism sets the background color of an item to that default selection blue as long as it is selected.

    And if I deselect the selected item and then set the background color to another one than the default, the the listviewitems flicker everytime you click on an item.

    Wasn't able to handle this, yet...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width