如何从TreeView控件的复选框中检索选中的值 [英] How to Retrive checked values from checkbox in treeview control

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

问题描述

亲爱的所有人,

列表框和Treeview控件有一个小问题.

我期望的是,当页面正在加载时,表中的所有值都需要在列表框中填充.

问题是,当我选择任何列表框项目时,该项目下的适当值需要绑定到树"视图.

例如我有两个这样的表,

Dear all,

I have a small problem with list box and Treeview controls.

What i am expecting is, when the page is loading all the values in the table need to be populated in the listbox.

The problem is, when i select any listbox item the appropriate values under that item need to be bind over to Tree view.

for example i have two tables like this,

Id  Name
1   A
2   B
3   C







SubId	ID	Names
1	1	Apple
2	1	Ant
3	1	Aeroplane
4	2	Ball
4	2	Banana
5	3	Cat





当我自动在列表框中选择名称A时,它需要从其他与名称A相关的表中获取数据,并将这些值也与复选框绑定到树视图节点.

当我在树状视图中选中某些复选框后,我需要从数据库中获取其ID并进行显示.


请尽快帮助我.



谢谢,
Sandeep





When i select name A in the listbox automatically it need to get the data from the other table related to name A and bind those values to treeview nodes with checkboxes also.

After when i check some checkboxes in the tree view i need to get their Id''s from the database and display.


Please help me as soon as possible.



Thanks,
Sandeep

推荐答案

要仅获取选中的复选框,您需要遍历所有节点.您需要递归.
To get only checked checkbox you need to travel through all nodes. you need recursion.
//on Submit Click get only checked checkbox
foreach (TreeNode tNode in TreeView1.Nodes)
  {
    chknode(tNode);
  }


public void chknode(TreeNode tn)
{
   string szFilePath;
   foreach (TreeNode tnn in tn.Nodes)
   {
      if (tnn.Checked)
         //your code goes here
   }
   chknode(tnn);
}



这是项艰巨的任务,到目前为止您尝试了什么?您可以粘贴代码吗?



It''s a snall assignment, what have you tried so far ? can you paste your code ?


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

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