public partial class ProductList : Form ...{ public ProductList() ...{ InitializeComponent(); } PageBar pb = new PageBar(); string[] ColumnValue =...{ "prdclass", "prdname" }; DataSet ds = XZD_Product.GetAllProductClass(); private void ProductList_Load(object sender, EventArgs e) ...{ TreeNodeCollection tnc; int NodeIndex=0;//第几个菜单 int step=0;//菜单级别 int j; if (ds.Tables[0].Rows.Count > 0) ...{ tnc=treeView1.Nodes; tnc.Add(ds.Tables[0].Rows[0]["prdclass"].ToString(), ds.Tables[0].Rows[0]["prdname"].ToString()); ds.Tables[0].Rows[0]["prdname"] = step;// for (int i = 1; i < ds.Tables[0].Rows.Count; i++) ...{ //兄弟节点 if (ds.Tables[0].Rows[i]["prdclass"].ToString().Length == ds.Tables[0].Rows[i-1]["prdclass"].ToString().Length) ...{ tnc.Add(ds.Tables[0].Rows[i]["prdclass"].ToString(), ds.Tables[0].Rows[i]["prdname"].ToString()); ds.Tables[0].Rows[i]["prdname"] = step;// NodeIndex++; } //子节点 else if (ds.Tables[0].Rows[i]["prdclass"].ToString().Length > ds.Tables[0].Rows[i - 1]["prdclass"].ToString().Length) ...{ step = step + 1; tnc = tnc[NodeIndex].Nodes; tnc.Add(ds.Tables[0].Rows[i]["prdclass"].ToString(), ds.Tables[0].Rows[i]["prdname"].ToString()); ds.Tables[0].Rows[i]["prdname"] = step;// NodeIndex = 0; } //既非兄弟节点,也不是子节点 else ...{ for (j = i-1; j > 0; j--) ...{ if (ds.Tables[0].Rows[j]["prdclass"].ToString().Length < ds.Tables[0].Rows[i]["prdclass"].ToString().Length) ...{ if (ds.Tables[0].Rows[i]["prdclass"].ToString().Substring(0,ds.Tables[0].Rows[j]["prdclass"].ToString().Length).Equals(ds.Tables[0].Rows[j]["prdclass"].ToString())) ...{ int k = int.Parse(ds.Tables[0].Rows[j]["prdname"].ToString()); //int k = 1; step = k + 1; tnc = treeView1.Nodes; for (; k >= 0; k--) ...{ tnc = tnc[tnc.Count-1].Nodes; } tnc.Add(ds.Tables[0].Rows[i]["prdclass"].ToString(), ds.Tables[0].Rows[i]["prdname"].ToString()); ds.Tables[0].Rows[i]["prdname"] = step; NodeIndex = tnc.Count-1; break;//找到父节点,退出循环 } } } //未找到父节点,说明是0级菜单 if (j == 0) ...{ tnc = treeView1.Nodes; step = 0; tnc.Add(ds.Tables[0].Rows[i]["prdclass"].ToString(), ds.Tables[0].Rows[i]["prdname"].ToString()); ds.Tables[0].Rows[i]["prdname"] = step; NodeIndex = tnc.Count - 1; } } } } //分页处理 pb.SetColumn(ColumnValue); c1FlexGrid1.DataSource = pb.GetFirstPageDataSource(ds); c1FlexGrid1.Cols["prdclass"].Width = 100; c1FlexGrid1.Cols["prdclass"].Caption = "产品编号"; c1FlexGrid1.Cols["prdname"].Width = 220; c1FlexGrid1.Cols["prdname"].Caption = "产品名称"; } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) ...{ //treeView1. string name = treeView1.SelectedNode.Name; ds = XZD_Product.GetSpecilProductClass(name); //分页处理 pb.SetColumn(ColumnValue); c1FlexGrid1.DataSource = pb.GetFirstPageDataSource(ds); c1FlexGrid1.Cols["prdclass"].Width = 100; c1FlexGrid1.Cols["prdclass"].Caption = "产品编号"; c1FlexGrid1.Cols["prdname"].Width = 220; c1FlexGrid1.Cols["prdname"].Caption = "产品名称"; }