[英]Using a Treeview with Checkboxes
I have treeView
that has several Nodes
like this 我的
treeView
有几个像这样的Nodes
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
. 在每个节点内有4个
checkboxes
- Answer A, Answer B, Answer C, Answer D
,具体取决于单击哪个复选框,节点的文本将变为Question1 - A,B,C,D
。 The answer to the question could mean all,one,two,three or none of the checkboxes
are clicked. 该问题的答案可能意味着全部,一个,两个,三个或没有一个
checkboxes
被单击。 What im trying to do is remove the letter if a checkbox
is unchecked
My Code: 什么即时试图做的是去除信,如果一个
checkbox
被unchecked
我的代码:
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
... 等等其他
checkBoxes
...
The Code above works fine when selecting
a checkBoxes
but not when deselecting
上面的代码在
selecting
checkBoxes
时工作正常,但在deselecting
时则不能正常工作
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.