WPF中绑定treeview

来源:转载

    void GetChildTVI(Node pnode, string pcode)

        {            string sQuery = string.Format("SELECT * FROM CRNATUREM0 WHERE parentid='{0}' AND dsblflag=0 ORDER BY seqnumbr", pcode);
            DataSet dset = gs.GetDataBySql(sQuery);
            if (dset != null && dset.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dset.Tables[0].Rows)
                {

                    TreeViewItem tvis = new TreeViewItem();
                    tvis.Header = string.Format("[{0}]{1}", dr["natureid"].ToString(), dr["naturenm"].ToString());
                    tvis.IsExpanded = true;
                    Nature c = new Nature();
                    c.ParentID = pcode;
                    c.NatureID = dr["natureid"].ToString();
                    c.NatureName = dr["naturenm"].ToString();
                    c.isDisabled = (bool)dr["dsblflag"];

                    tvis.Tag = c;

                    Node cn = new Node();
                    cn.CallNature = c;
                    cn.Title = string.Format("[{0}]{1}", dr["natureid"].ToString(), dr["naturenm"].ToString());
                    cn.IsDisabled = (bool)dr["dsblflag"];

                    GetChildTVI(cn, c.NatureID);
                    if (cn.ChildNodes.Count > 0)
                        cn.IsVisibled = Visibility.Collapsed;
                    pnode.ChildNodes.Add(cn);
                }

            }

        }

本文来自miyabaobeii的博客,原文地址:http://blog.csdn.net/miyabaobeii/archive/2011/06/13/6541065.aspx


分享给朋友:
您可能感兴趣的文章:
随机阅读: