-1
我有一個複選框列表,需要更改爲treeview。我這樣做了,但現在我想要的是檢索樹視圖上檢查的項目(onclick),就像它在checkboxlist上完成的那樣。 在複選框列表中,我可以只用cblist.Items [k]獲取項目。已選中
我該如何使用treeview來做到這一點?從CheckboxList到Treeview
另一個問題,我怎麼能算他們?
private void Tree()
{
try
{
Dados d = new Dados();
DataTable dtTree = d.getTreeView("%");
DataSet ds = new DataSet("table");
ds.Tables.Add(dtTree);
ds.Relations.Add("ChildRows", ds.Tables[0].Columns["ID"],
ds.Tables[0].Columns["ParentID"]);
foreach (DataRow level1DataRow in ds.Tables[0].Rows)
{
if (string.IsNullOrEmpty(level1DataRow["ParentID"].ToString()))
{
TreeNode parentTreeNode = new TreeNode();
parentTreeNode.Text = "<span style=\"color:" + level1DataRow["Color"].ToString() + "\">" + level1DataRow["Description"].ToString() + "</span>";
GetChildRows(level1DataRow, parentTreeNode);
Treeview1.Nodes.Add(parentTreeNode);
}
}
}
catch (Exception ex)
{
//something
}
}
private void GetChildRows(DataRow dataRow, TreeNode treeNode)
{
DataRow[] childRows = dataRow.GetChildRows("ChildRows");
foreach (DataRow row in childRows)
{
TreeNode childTreeNode = new TreeNode();
childTreeNode.Text = "<span style=\"color:" + row["Color"].ToString() +"\">" + row["Description"].ToString() +"</span>";
childTreeNode.Value = row["LocalID"].ToString();
treeNode.ChildNodes.Add(childTreeNode);
if (row.GetChildRows("ChildRows").Length > 0)
{
GetChildRows(row, childTreeNode);
}
}
}
而且CheckBoxList的
顯示一些代碼伴侶。 –