Drawing Your Own Controls Using GDI+
This control is demonstrated as part of the same sample as the data-bound TreeView, and is used to display all of the books for a particular author or publisher
Details development of a data-bound, owner-drawn control using GDI+ as one of series of Microsoft Windows control development samples to be read in conjunction with an associated overview article
http://msdn.microsoft.com/library/en-us/dnwinforms/html/custcntrlsamp4.asp
This control is demonstrated as part of the same sample as the data-bound TreeView, and is used to display all of the books for a particular author or publisher
Details development of a data-bound, owner-drawn control using GDI+ as one of series of Microsoft Windows control development samples to be read in conjunction with an associated overview article
http://msdn.microsoft.com/library/en-us/dnwinforms/html/custcntrlsamp4.asp
{
DataSet myRootDataSet=ExecuteSelectSql(selectStatement,"myRootNode");
DataView dataView=new DataView(myRootDataSet.Tables["myRootNode"]);
string aa= idFieldName+"="+parentIDFieldName;
dataView.RowFilter=aa;
foreach(DataRowView myRoot in dataView)
{
myTreeViewName.Nodes.Clear();
TreeNode myTreeNode =new TreeNode();
//myTreeNode.Text=myRoot[""+txtFieldName+""].ToString();
myTreeNode.Text = "<span onmouseover=javascript:title='"+myRoot[""+txtFieldName+""].ToString()+"'>"+myRoot[""+txtFieldName+""].ToString()+"</span>";
myTreeNode.ID=myRoot[""+ idFieldName +""].ToString();
myTreeNode.NavigateUrl=urlStr + myRoot[""+urlFieldName+""].ToString();
myTreeNode.Target=targetName;
myTreeViewName.Nodes.Add(myTreeNode);
FillChildTree(myTreeNode.Nodes,myTreeNode.ID,myRootDataSet.Tables["myRootNode"],parentIDFieldName,idFieldName,txtFieldName,urlStr,urlFieldName,targetName);
}
}
private void FillChildTree(TreeNodeCollection TNC,string classParentID,DataTable myDataTable,string parentIDFieldName,string idFieldName,string txtFieldName,string urlStr,string urlFieldName,string targetName)
{
DataView myDataView=new DataView(myDataTable);
myDataView.RowFilter=""+parentIDFieldName+"="+classParentID+" and "+idFieldName+"<>"+parentIDFieldName+"";
foreach(DataRowView drv in myDataView)
{
TreeNode tn = new TreeNode();
tn.ID = drv[""+ idFieldName +""].ToString();
//tn.Text = drv[""+TxtFieldName+""].ToString();
tn.Text = "<span onmouseover=javascript:title='"+drv[""+txtFieldName+""].ToString()+"'>"+drv[""+txtFieldName+""].ToString()+"</span>";
tn.NavigateUrl=urlStr + drv[""+urlFieldName+""].ToString();
tn.Target=targetName;
TNC.Add(tn);
FillChildTree(tn.Nodes,tn.ID,myDataTable,parentIDFieldName,idFieldName,txtFieldName,urlStr,urlFieldName,targetName);
}
}
System.Windows.Forms.TreeNode mNode=new TreeNode("全部");
//mNode.ImageIndex =1;
treeView1.Nodes.Add(mNode) ;
//假设DataSet 已经取得
System.Windows.Forms.TreeNode nNode=new TreeNode("在职");
System.Windows.Forms.TreeNode pNode=new TreeNode("离职");
treeView1.TopNode.Nodes.Add(nNode) ;
treeView1.TopNode.Nodes.Add(pNode) ;
treeView1.Select ();
if (ds.Tables [0].Rows.Count <=0 )
{
return;
}
else
{
// add Add some childtreenodes
foreach(DataRow dr in ds.Tables [0].Rows )
{
System.Windows.Forms.TreeNode aNode=new TreeNode(dr["Name"].ToString() );
System.Windows.Forms.TreeNode bNode=new TreeNode(dr["Name"].ToString());
treeView1.Nodes [0].Nodes[0].Nodes .Add (aNode);
treeView1.Nodes [0].Nodes[1].Nodes .Add (bNode);
}
}
}
}