Reputation: 1119
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
Upvotes: -1
Views: 101
Reputation: 480
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;
}
}
Upvotes: 1