Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    Sacramento, CA
    Posts
    193
    Thanks
    3
    Thanked 1 Time in 1 Post

    Treeview Background Color (Access 2007)

    Anyone have any idea if the background color of a treeview can be set via vba code? And, if so, can you point me to or provide an example.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Treeview Background Color (Access 2007)

    The treeview control has no built-in support for this; you need to use Windows API functions.

    Copy the code from the attached text file (source: VB Helper Tutorial: Background Color) into a new standard module, and use a line like the following in the On Load event of the form with the treeview control:

    ChangeBackgroundColor Me.Treeview1.hWnd, vbRed

    Replace Treeview1 with the name of the treeview control and vbRed with the color that you want to use. You can use a symbolic constant for a literal color such as vbRed, a system color such as vbInfoBackground, or an RGB value such as RGB(255, 0, 128).

    Important: treeview nodes are *not* transparent, so you have to set the BackColor property of the nodes too.
    Attached Files Attached Files

  3. #3
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    Sacramento, CA
    Posts
    193
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Treeview Background Color (Access 2007)

    Hans,

    Thanks much. However, there must be one more consideration I'm overlooking. I have a three level tree and, between your code and setting the BackColor as I build each node level, the BackColor seems to work with the exception of the last items at each level. eg ( The last Level 1 node doesn't have the color set in the narrow band/column under its + for each Level 2 item. Similarly, the last Level 2 node under each Level 1 node has the same effect, the color is not set under its + for each Level 3 item. And finally, the last Level 3 node under each Level 2 has the same no-color problem for each item.) My sequence for the Treeview is: set the treeview properties, create Level 1 node items with BackColor, create Level 2 nodes with BackColor, create Level 3 nodes with BackColor and finally set the Treeview BackColor with your code. Thinking it might be a timing issue, I've tried moving the ChangeBackgroundColor to before and aslo after the setting of its general properties ... no difference.

    Appreciate any insights you have,
    Marty

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Treeview Background Color (Access 2007)

    Using Windows API functions is a "dirty" trick - the treeview control was not designed with a non-standard background color in mind, so it behaves unpredicatably if you set the background color anyway. I think you'll have to choose between not setting the background color (which would be my preference) and living with the quirks if you do.

  5. #5
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    Sacramento, CA
    Posts
    193
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Treeview Background Color (Access 2007)

    Was hoping your response would be to set a property, fix the sequence or some such thing. It'll be up to the client on whether to BackColor or not.

    Thanks again for your help,
    Marty

Posting Permissions

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