如何通过TreeView控件中的复选框默认检查为true [英] How to default checked true by checkboxes in treeview control

查看:98
本文介绍了如何通过TreeView控件中的复选框默认检查为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用Treeview控件并将树视图控件与xml绑定.我将teeview属性设置为ShowCheckBoxes = All.我的要求是页面加载,默认情况下,treview控件应选中所有复选框.即已检查为真.我要求对此提供帮助.

谢谢
Mahesh.

Hi,

I am using Treeview control and binding the tree view control with xml. I set the teeview property as ShowCheckBoxes=All. My requirement is on page load, treview control should select all the check boxes by default. i.e Checked is true. I request please help me out on this.

Thanks
Mahesh.

推荐答案

foreach (TreeNode node in tv.Nodes)
{
node.Checked = true;
if(node.ChildNodes.Count > 0)
    checkChildNode(node);
}

private void checkChildNode(TreeNode node)
{
            foreach (TreeNode chNode in node.ChildNodes)
            {
                chNode.Checked = true;
                if (chNode.ChildNodes.Count > 0)
                    checkChildNode(chNode);
            }
}



如果这对您有帮助,请投票并将其标记为答案.



If this helped you then please Vote and mark it as answer.


使用此代码


USE THIS CODE


For I As Integer = 0 To TreeView1.Nodes.Count
        TreeView1.Nodes(I).Checked = True
    Next



可以帮助您...
通过评论PLS ...



MAY HELP U...
PASS A COMMENT PLS...


嗨rajivlipu,

使用上面的代码,它仅选择顶部节点.我需要选择所有节点,即包括子节点的顶部到底部节点.我请求您可以帮我吗.


谢谢
Mahesh.
Hi rajivlipu,

Using the above code, it selecting only the top node only. I need to select all the nodes i.e top to bottom nodes including childs. I Request can you help me on this.


Thanks
Mahesh.


这篇关于如何通过TreeView控件中的复选框默认检查为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆