SoFunction
Updated on 2025-03-07

treeview checkbox related questions

private void Display()
{
dt = new TsOrganize().OrganizeDs();
DataView dv = new DataView(dt);
TreeNode nodes = new TreeNode();
= "Coffee on both sides of the * Strait";
= "0";
if ( >= 1)
{
= "fParentId=''";
if ( >= 1)
{
foreach (DataRowView drrow in dv)
{
TreeNode nodel = new TreeNode();
= ["fOrgName"].ToString();
= ["forgNo"].ToString();
(nodel);
NodeList(dv, nodel, ["fOrgNo"].ToString());
}
}
}
(nodes);
}

//Spanning Tree
private void NodeList(DataView dv, TreeNode node, string ParentId)
{
= "fParentId='" + () + "'";
if ( >= 1)
{
foreach (DataRowView drrow in dv)
{
TreeNode nodel = new TreeNode();
= ["fOrgName"].ToString();
= ["forgNo"].ToString();
(nodel);
NodeList(dv, nodel, ["fOrgNo"].ToString());
}
}
}
============================================================
1.
TreeNodeCollection tnc = ;
//Get all selected nodes in the tree
private void GetCheckNode(TreeNodeCollection tnc)
{
foreach (TreeNode node in tnc)
{
if()
{
if ( == 0)
{
DataRow dr = ();
dr["forgNo"] = ;
dr["fOrgName"] = ();
(dr);
}
}
}
}

2. According to the value in the database, give the corresponding node CHECKED=true

/// <summary>
///dtPloyStore: is a table (saves data read from the database)
/// <para></para>
/// </summary>
TreeNodeCollection tnc = ;
if (dtPloyStore != null)
{
if ( > 0)
{
for (int i = 0; i < ; i++)
{
GetSelectedTreeNode(tnc, [i]["fOrgNo"].ToString());
}
}
}
/// <summary>
/// traverse the store tree and get the selected node
/// <para></para>
/// </summary>
/// <param name="tnc"></param>
public void GetSelectedTreeNode(TreeNodeCollection tnc,string CheckData)
{
foreach (TreeNode node in tnc)
{
if ()
{
= true;
break;
}
GetSelectedTreeNode(, CheckData);
}
}

Implement the selection of the parent node and the child nodes automatically select
///Add attributes to treeview in the background
/// ("onclick", "OnTreeNodeChecked()");

///The following is written in the foreground javascript
function OnTreeNodeChecked() {
var ele = ;
if ( == 'checkbox') {
var childrenDivID = ('CheckBox', 'Nodes');
var div = (childrenDivID);
if (div == null) return;
var checkBoxs = ('INPUT');
for (var i = 0; i < ; i++) {
if (checkBoxs[i].type == 'checkbox')
checkBoxs[i].checked = ;
}
}
4. Displaying CHECKBOX on treeview is actually very simple. Just set ShowCheckBoxes="All"
If we want to display the setting layer of treeviw, we can set ExpandDepth="N" (N is the number, which is the number of layers you want to display, and 0 is all layers)