日期:2014-05-19  浏览次数:20846 次

一个节点都是checkbox的treeview如何使某一个节点选中后其子节点都自动默认选中?
把一个treeview的checkboxs属性设为true使其节点都变成checkbox之后,想实现使某一个节点选中后其子节点都自动默认选中该怎么做呢?大家帮忙,谢谢拉!!

------解决方案--------------------
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
foreach (System.Windows.Forms.TreeNode node in e.Node.Nodes)
{
node.Checked = e.Node.Checked;
}
}
------解决方案--------------------
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
foreach (System.Windows.Forms.TreeNode node in e.Node.Nodes)
{
node.Checked = true;
}
}

------解决方案--------------------
<script language = "javascript " type= "text/javascript ">
function client_OnTreeNodeChecked()
{
var obj = window.event.srcElement;
var treeNodeFound = false;
var checkedState;
if (obj.tagName == "INPUT " && obj.type == "checkbox ")
{
var treeNode = obj;
checkedState = treeNode.checked;
do
{
obj = obj.parentElement;
}
while (obj.tagName != "TABLE ")
var parentTreeLevel = obj.rows[0].cells.length;
var parentTreeNode = obj.rows[0].cells[0];
var tables = obj.parentElement.getElementsByTagName( "TABLE ");
var numTables = tables.length
if (numTables > = 1)
{
for (i=0; i < numTables; i++)
{
if (tables[i] == obj)
{
treeNodeFound = true;
i++;
if (i == numTables)
{
return;
}
}
if (treeNodeFound == true)
{
var childTreeLevel = tables[i].rows[0].cells.length;
if (childTreeLevel > parentTreeLevel)
{
var cell = tables[i].rows[0].cells[childTreeLevel - 1];
var inputs = cell.getElementsByTagName( "INPUT ");
inputs[0].checked = checkedState;
}
else
{
return;
}
}
}
}
}
}

</script>
.cs代码
TreeView1.Attributes.Add( "onclick ", "return client_OnTreeNodeChecked(); ");