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