-1

I have treeView that has several Nodes like this

Question 1 Question 2 Question 3 Question 4 

Inside each of those node there are 4 checkboxes - Answer A, Answer B, Answer C, Answer D, depending on whichever checkbox is clicked the text of a Node will change to Question1 - A,B,C,D. The answer to the question could mean all,one,two,three or none of the checkboxes are clicked. What im trying to do is remove the letter if a checkbox is unchecked My Code:

private void ckbAnswerA_CheckedChanged(object sender, EventArgs e) { updateAnswerA(); } void updateAnswerA() { var words = new List<string>(); if (ckbOption1.Checked) { words.Add("A,"); treeView1.SelectedNode.Text += string.Join(" ", words); } 

Etc for the other checkBoxes...

The Code above works fine when selecting a checkBoxes but not when deselecting

2
  • I just noticed something that wasn't in the previous question, you are adding the text after each check whereas it should be done after all boxes have been checked! Commented Mar 24, 2016 at 12:11
  • ok, do you mean putting all the If Statements in one method? Commented Mar 24, 2016 at 12:15

1 Answer 1

1

I manually way, I hope you get the idea.

private void ckbAnswerA_CheckedChanged(object sender, EventArgs e) { if (ckbAnswerA.Checked) { updateAnswerA(true); } else { updateAnswerA(false); } } private void updateAnswerA(bool flag) { if(flag) { var words = new List<string>(); words.Add("A,"); treeView1.SelectedNode.Text += string.Join(" ", words); } else { string update = treeView1.SelectedNode.Text; update = update.Replace("A,", ""); treeView1.SelectedNode.Text = update; } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.