Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. disabling/greying a treeview node

disabling/greying a treeview node

Scheduled Pinned Locked Moved C#
csharpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vlusardi
    wrote on last edited by
    #1

    In a C# Windows Form, I have a treeview/listview pair that behaves like Windows Explorer, displaying drives, folders and files... I want to display certain treeview nodes as disabled or greyed... Can someone tell me how this can be done? thanks very much.

    D 1 Reply Last reply
    0
    • V vlusardi

      In a C# Windows Form, I have a treeview/listview pair that behaves like Windows Explorer, displaying drives, folders and files... I want to display certain treeview nodes as disabled or greyed... Can someone tell me how this can be done? thanks very much.

      D Offline
      D Offline
      Don_s
      wrote on last edited by
      #2

      A simple solution that may do what you want is to simply set the ForeColor of the node you want greyed to Color.Gray or Color.LightGray. You can then handle the BeforeSelect event of the treeview and check for the fore color, if it is Color.Gray or Color.LightGray, depending on which you choose, set the Cancel property of the TreeViewCancelEventArgs to true:

      private void treeView1_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
      {
      	if(e.Node.ForeColor == Color.Gray)
      	{
      	 e.Cancel = true;
      	}
      }
      

      Hope this is useful

      V 1 Reply Last reply
      0
      • D Don_s

        A simple solution that may do what you want is to simply set the ForeColor of the node you want greyed to Color.Gray or Color.LightGray. You can then handle the BeforeSelect event of the treeview and check for the fore color, if it is Color.Gray or Color.LightGray, depending on which you choose, set the Cancel property of the TreeViewCancelEventArgs to true:

        private void treeView1_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
        {
        	if(e.Node.ForeColor == Color.Gray)
        	{
        	 e.Cancel = true;
        	}
        }
        

        Hope this is useful

        V Offline
        V Offline
        vlusardi
        wrote on last edited by
        #3

        Yo Don, thanks for the tip, that will do nicely...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups