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. How to change BG color of tree node on click event

How to change BG color of tree node on click event

Scheduled Pinned Locked Moved C#
data-structureshelptutorial
9 Posts 3 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.
  • R Offline
    R Offline
    rfresh
    wrote on last edited by
    #1

    I have a Treeview with checkboxes. I want to be able to click on a checkbox and change the node BG color. If the checkbox is unchecked then I want to default BG color. I've searched around and saw some things that were close but didn't exactly do both of these things. Thanks for any help...

    M B 2 Replies Last reply
    0
    • R rfresh

      I have a Treeview with checkboxes. I want to be able to click on a checkbox and change the node BG color. If the checkbox is unchecked then I want to default BG color. I've searched around and saw some things that were close but didn't exactly do both of these things. Thanks for any help...

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Assuming you are using winforms - you don't mention your UI. Look for a NodeClick event, in that event you write your code based on the content of the node (sender, although the sender may be the treeview and you need the SelecteNode).

      Never underestimate the power of human stupidity RAH

      R 3 Replies Last reply
      0
      • R rfresh

        I have a Treeview with checkboxes. I want to be able to click on a checkbox and change the node BG color. If the checkbox is unchecked then I want to default BG color. I've searched around and saw some things that were close but didn't exactly do both of these things. Thanks for any help...

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        Please start posting these kinds of questions in Q&A, clearly tagging them to indicate if they are WinForms, WPF, or whatever. My sense is you are not spending enough time really studying how to use .NET controls, and you are asking for "more help than you really need," far too frequently. Do you have a good book on basic WinForms programming with example code for you to study, and use ? imho, there's no substitute for hands-on careful study, on your own, with the WinForms Controls: most of them are really kind of "fossils" from the old days of COM and ActiveX, dressed-up for the .NET party, and each of them has their own "quirks." The Visual Studio IDE and Property Browser are great tools for studying what the defaults of Control Properties are, and what Properties, and Events, and settings, are available. Experiment ! imho, you also need to spend a little time studying the CodeProject guidelines, and how CP works. I, and others will, I'm sure, be happy to assist you to "walk forwards along" the path towards mastery of WinForms, but I, and most likely others, will not "carry you;" if we did, you would not really learn. yours, Bill

        ~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

        R 1 Reply Last reply
        0
        • M Mycroft Holmes

          Assuming you are using winforms - you don't mention your UI. Look for a NodeClick event, in that event you write your code based on the content of the node (sender, although the sender may be the treeview and you need the SelecteNode).

          Never underestimate the power of human stupidity RAH

          R Offline
          R Offline
          rfresh
          wrote on last edited by
          #4

          Thumbs up...thanks...

          1 Reply Last reply
          0
          • B BillWoodruff

            Please start posting these kinds of questions in Q&A, clearly tagging them to indicate if they are WinForms, WPF, or whatever. My sense is you are not spending enough time really studying how to use .NET controls, and you are asking for "more help than you really need," far too frequently. Do you have a good book on basic WinForms programming with example code for you to study, and use ? imho, there's no substitute for hands-on careful study, on your own, with the WinForms Controls: most of them are really kind of "fossils" from the old days of COM and ActiveX, dressed-up for the .NET party, and each of them has their own "quirks." The Visual Studio IDE and Property Browser are great tools for studying what the defaults of Control Properties are, and what Properties, and Events, and settings, are available. Experiment ! imho, you also need to spend a little time studying the CodeProject guidelines, and how CP works. I, and others will, I'm sure, be happy to assist you to "walk forwards along" the path towards mastery of WinForms, but I, and most likely others, will not "carry you;" if we did, you would not really learn. yours, Bill

            ~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

            R Offline
            R Offline
            rfresh
            wrote on last edited by
            #5

            I'll post in the Q&A as you suggest. I'm a bit older and the C# and .net coding is harder for me to grasp. I do spend a lot of time googling for answers but often the code I find I just don't understand it. For example, I do see that Sender arg a lot and try to use it like Sender.Checked on a node checkbox but that doesn't work. I also see the e args and try using e.Checked and that doesn't work. sometimes the this. member works ok and other times not. Seems to me if your coding in C# that the C# group would be where one should post vs the Q&A but I'm sure you have a reason for asking me to not post here in C#.

            B 1 Reply Last reply
            0
            • M Mycroft Holmes

              Assuming you are using winforms - you don't mention your UI. Look for a NodeClick event, in that event you write your code based on the content of the node (sender, although the sender may be the treeview and you need the SelecteNode).

              Never underestimate the power of human stupidity RAH

              R Offline
              R Offline
              rfresh
              wrote on last edited by
              #6

              Thanks...with your help, I got it to work...in this case with that little 'e' arg:

                  private void treeView\_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
                  {
                      if (e.Node.Checked)
                      {
                          e.Node.BackColor = Color.Yellow;
                      }
                      else
                      {
                          e.Node.BackColor = Color.White;
                      }
                  }
              
              1 Reply Last reply
              0
              • M Mycroft Holmes

                Assuming you are using winforms - you don't mention your UI. Look for a NodeClick event, in that event you write your code based on the content of the node (sender, although the sender may be the treeview and you need the SelecteNode).

                Never underestimate the power of human stupidity RAH

                R Offline
                R Offline
                rfresh
                wrote on last edited by
                #7

                BTW, I placed my cursor on the 'TreeNodeMouseClickEventArgs' argument in VS 2012 and pressed F1 for the MSDN help on what that 'e' represents and it mentioned nothing about it. What is that called anyway?

                1 Reply Last reply
                0
                • R rfresh

                  I'll post in the Q&A as you suggest. I'm a bit older and the C# and .net coding is harder for me to grasp. I do spend a lot of time googling for answers but often the code I find I just don't understand it. For example, I do see that Sender arg a lot and try to use it like Sender.Checked on a node checkbox but that doesn't work. I also see the e args and try using e.Checked and that doesn't work. sometimes the this. member works ok and other times not. Seems to me if your coding in C# that the C# group would be where one should post vs the Q&A but I'm sure you have a reason for asking me to not post here in C#.

                  B Offline
                  B Offline
                  BillWoodruff
                  wrote on last edited by
                  #8

                  Hi RFresh, It's not my intention to be critical, or patronizing, but I do think that if you are at the point where you don't have a clear grasp of the fundamentals of what a WinForms EventHandler, and its sender/EventArgs parameters, are, you may be studying "hard," but not "smart." I strongly suggest you start off by using a resource like this free book, "Dot Net Book Zero," by Charles Petzold [^], and bear down it. Or, Jesse Liberty's over-view books on C# are excellent (O'Reilly). If you are coming from a deep-background in COM, ActiveX, C/C++, to WinForms, then I'd recommend Chris Sell's book on Windows Forms (Addison-Wesley); disclaimer: I was a paid technical editorial assistant on that book. Just to be clear, my opinion that the type of specific questions you are asking on this Forum (now) are best served in Q&A, are just my opinion, and I do not represent, or speak for, CP in any way. The general idea is that forums like this one are meant to be for discussion of broader issues in using C# ... but that's my interpretation. good luck, Bill (who started programming after age forty)

                  ~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

                  R 1 Reply Last reply
                  0
                  • B BillWoodruff

                    Hi RFresh, It's not my intention to be critical, or patronizing, but I do think that if you are at the point where you don't have a clear grasp of the fundamentals of what a WinForms EventHandler, and its sender/EventArgs parameters, are, you may be studying "hard," but not "smart." I strongly suggest you start off by using a resource like this free book, "Dot Net Book Zero," by Charles Petzold [^], and bear down it. Or, Jesse Liberty's over-view books on C# are excellent (O'Reilly). If you are coming from a deep-background in COM, ActiveX, C/C++, to WinForms, then I'd recommend Chris Sell's book on Windows Forms (Addison-Wesley); disclaimer: I was a paid technical editorial assistant on that book. Just to be clear, my opinion that the type of specific questions you are asking on this Forum (now) are best served in Q&A, are just my opinion, and I do not represent, or speak for, CP in any way. The general idea is that forums like this one are meant to be for discussion of broader issues in using C# ... but that's my interpretation. good luck, Bill (who started programming after age forty)

                    ~ “This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

                    R Offline
                    R Offline
                    rfresh
                    wrote on last edited by
                    #9

                    Bill, Thanks for the pointers...I will get Charles' book.

                    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