Click here to Skip to main content
15,923,168 members
Home / Discussions / C#
   

C#

 
GeneralCheckbox should delete any childnode but not the root node. Can someone please help?? [modified] Pin
T4AMD28-Dec-07 8:18
T4AMD28-Dec-07 8:18 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
KaptinKrunch28-Dec-07 8:36
KaptinKrunch28-Dec-07 8:36 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
T4AMD28-Dec-07 8:54
T4AMD28-Dec-07 8:54 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
KaptinKrunch28-Dec-07 9:01
KaptinKrunch28-Dec-07 9:01 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
T4AMD28-Dec-07 9:09
T4AMD28-Dec-07 9:09 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
KaptinKrunch28-Dec-07 9:21
KaptinKrunch28-Dec-07 9:21 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
T4AMD28-Dec-07 10:21
T4AMD28-Dec-07 10:21 
GeneralRe: Checkbox should delete any childnode but not the root node. Can someone please help?? Pin
KaptinKrunch28-Dec-07 10:50
KaptinKrunch28-Dec-07 10:50 
Ok lets see here.

if(TreeViewNode.Level == 0)
{
//you know this is a root node(because the level is equal to zero, the first level of nodes!) so do not do anything!
}
else
{
//this is a child node so lets remove it.
}

<br />
private bool CheckBox(TreeNode tn)<br />
{<br />
  //is the selected node checked<br />
  if (tn.Checked == false)<br />
  {<br />
    //is the selected node a root node<br />
    if(tn.Level != 0)<br />
    {<br />
      //NO so we remove it<br />
      tn.Remove();<br />
<br />
      //indicate that it successfully removed the node<br />
      return true;<br />
    }<br />
    else<br />
    {<br />
      //the selected node is a root node. DO NOT REMOVE.<br />
      return false;<br />
    }<br />
  }<br />
  else<br />
  {<br />
    //selected node is not checked.<br />
    return false;<br />
  }<br />
}<br />


use this function like this

<br />
if(CheckBox(tvFavorites.SelectedNode) == true)<br />
  MessageBox.Show("It was removed.");<br />
else<br />
  MessageBox.Show("Its still there.");<br />



Good Luck.

Just because we can; does not mean we should.

QuestionC#, WPF, XmlDataProvider, and binding to an XML file. Pin
Lily Bristol28-Dec-07 7:06
Lily Bristol28-Dec-07 7:06 
GeneralRe: C#, WPF, XmlDataProvider, and binding to an XML file. Pin
KaptinKrunch28-Dec-07 8:32
KaptinKrunch28-Dec-07 8:32 
GeneralRe: C#, WPF, XmlDataProvider, and binding to an XML file. Pin
Lily Bristol2-Jan-08 7:55
Lily Bristol2-Jan-08 7:55 
GeneralA password problem Pin
Strategic_Thinker28-Dec-07 6:58
Strategic_Thinker28-Dec-07 6:58 
GeneralRe: A password problem Pin
Ed.Poore28-Dec-07 7:07
Ed.Poore28-Dec-07 7:07 
GeneralRe: A password problem Pin
Strategic_Thinker29-Dec-07 2:21
Strategic_Thinker29-Dec-07 2:21 
GeneralRe: A password problem Pin
Ed.Poore29-Dec-07 8:00
Ed.Poore29-Dec-07 8:00 
GeneralRe: A password problem Pin
CPallini28-Dec-07 7:27
mveCPallini28-Dec-07 7:27 
GeneralRe: A password problem Pin
Not Active28-Dec-07 7:30
mentorNot Active28-Dec-07 7:30 
GeneralC# Code Editor - recommendations [modified] Pin
User of Users Group28-Dec-07 5:27
User of Users Group28-Dec-07 5:27 
GeneralRe: C# Code Editor - recommendations Pin
Ed.Poore28-Dec-07 5:51
Ed.Poore28-Dec-07 5:51 
GeneralRe: C# Code Editor - recommendations Pin
User of Users Group28-Dec-07 7:08
User of Users Group28-Dec-07 7:08 
GeneralRe: C# Code Editor - recommendations Pin
Daniel Grunwald28-Dec-07 8:12
Daniel Grunwald28-Dec-07 8:12 
GeneralRe: C# Code Editor - recommendations Pin
TJoe28-Dec-07 9:38
TJoe28-Dec-07 9:38 
GeneralRe: C# Code Editor - recommendations Pin
User of Users Group28-Dec-07 12:00
User of Users Group28-Dec-07 12:00 
GeneralRe: C# Code Editor - recommendations Pin
Ed.Poore28-Dec-07 12:33
Ed.Poore28-Dec-07 12:33 
Generalplease delete thread.... Pin
shwaguy28-Dec-07 4:52
shwaguy28-Dec-07 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.