Namespace BQ_TREEVIEW
{///
/// BQ_TREEVIEW summary description
/// summary>
Public class bq_treeview: system.windows.Forms.treeView
{
Private system.componentmodel.Container Components = NULL;
PRIVATE DATATABLE M_TB = NULL;
PRIVATE STRING M_ROOTMAATID;
BQ_TREENODE ROOTNODE = NULL;
ArrayList alNode = new arraylist ();
Public BQ_TreeView ()
{
InitializationComponent ();
}
Protected Override Void Dispose (Bool Disposing)
{
IF (Disposing)
{
IF (Components! = NULL)
{
Components.dispose ();
}
}
Base.dispose (Disposing);
}
#REGION
Private vidinitiRizeComponent ()
{
Components = new system.componentmodel.container ();
}
#ndregion
///
// Define the data source
/// summary>
Public DataTable TreeDataSource
{
set
{
m_tb = value;
}
}
///
// / Clear information in all tree controls
/// summary>
Private void clear ()
{
IF (rootnode! = null)
{
Rootnode.nodes .clear ();
IF (rootnode! = null)
{
Try
{
Rootnode.remove ();
}
Catch
{}
}
}
IF (alNode! = NULL)
IF (alNode.count> 0)
Alnode.clear ();
}
///
/// Construct a tree control
/// summary>
Public void maketree ()
{
Clear (); // Clear resources in the tree node
Cursor.current = cursors.waitcursor;
// First, pay the root node because there is no information in the structure of the structure.
Rootnode = New BQ_TREENODE (M_Rootmatid);
Rootnode.matid = m_rootmatid;
AlNode.Add (rootnode);
this.nodes .add (rootnode);
Foreach (DataRow Row In M_TB.ROWS)
{
BQ_TREENODE FNODE = NULL;
BQ_TREENODE CNODE = NULL;
Cnode = MakeArray (Row ["ID"]. TOSTRING (), ROW ["Material Code"] .tostring (), OUT FNODE);
FNode.Nodes.Add (cnode);
}
Rootnode.expand ();
Cursor.current = CURSORS.DEFAULT;
}
//
/// Construct a dynamic array, analog tree control a bifurcated linear structure, each of which is the latest linear structure, this whole control is critical /// summary>
/// Level param>
/// Material code param>
/// Parent Node param>
///
Private BQ_Treenode Makerray (String Strid, String Matid, Out BQ_TREENODE NODEF) {
Try
{
BQ_TREENODE NODE = New BQ_TREENODE (MATID);
Node.matid = Matid;
BQ_TREENODE NODERET = NULL;
INT ngrade = int.parse (strid);
IF (ngrade == 0)
{
}
Else
{
IF (alNode.count> = NGRADE 1)
{
AlNode [ngrade] = node;
Noderet = (bq_treenode) alNode [NGRADE-1];
}
Else
{
AlNode.Add (Node);
Noderet = (bq_treenode) alNode [NGRADE-1];
}
}
Nodef = noderet;
Return node;
}
Catch (Exception E)
{
Throw New Exception ("", e);
}
}
Public String Rootmatid
{
get
{
Return M_RootmAtid;
}
set
{
M_RootmAtid = Value;
}
}
}
}
After compiling, you can add the control BQ_TREEVIEW, as shown below (Figure 2)
As long as it is in the app
write
BQ_TREEVIEW1.ROOTMAATID = STROOTID;
BQ_TREEVIEW1.TREEDASOSOURCE = TBPROINFO;
BQ_TREEVIEW1.MAKETREE ();
You can display the entire BOM structure, TBPROINFO is the table structure of the SQL statement above.
I hope this article is helpful for friends who have the same needs, and I will give you SQLSVER again, my email: gangleader@126.com