1. 程式人生 > >c#DevExpress元件TreeList控制元件自己控制節點圖示(二)

c#DevExpress元件TreeList控制元件自己控制節點圖示(二)

繫結樹節點及圖示狀態如下:

/// <summary>
        /// 繫結資料上報匯出樹
        /// </summary>
        private void BindJgsyTree()
        {
            JGSYTreeService jgsyTreeService = new JGSYTreeService();
            List<JGSYTree> listJgsyTree = jgsyTreeService.GetExportJgsyTree(Global.User.JS_USER_NAME);
            treeListJgsyCommon.Columns.Add();
            treeListJgsyCommon.Columns[0].Visible = true;
            treeListJgsyCommon.DataSource = listJgsyTree;
            treeListJgsyCommon.KeyFieldName = "JGSY_CODE";
            treeListJgsyCommon.ParentFieldName = "JGSY_PARENT_CODE";
            treeListJgsyCommon.Columns[0].FieldName = "JGSY_NAME";
            treeListJgsyCommon.ExpandAll();
            //ImageCollection imgCollection = TreeListImageState.GetImageCollection();
            treeListJgsyCommon.StateImageList = TreeListImageState.GetImageList();//imgCollection; //
            foreach (TreeListNode node in treeListJgsyCommon.Nodes)
            {
                node.StateImageIndex = (int)TreeNodeCheckImage.Loading;
                BindApplyStateChild(node, true);
            }

            //非同步更新是否有上報資料控制節點狀態
            BackgroundWorker bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler((sender1, e1) =>
            {
                InvokeSetControlEnable(false); 
                foreach (TreeListNode node in treeListJgsyCommon.Nodes)
                {
                    string jgsyCode = node.GetValue("JGSY_CODE").ToString();
                    bool applyState = jgsyTreeService.GetApplyState(jgsyCode);
                    if (applyState)
                        node.StateImageIndex = (int)TreeNodeCheckImage.UnCheckedBranch;
                    else
                        node.StateImageIndex = (int)TreeNodeCheckImage.DisCheckedBranch;
                    BindApplyStateChild(node, false);
                }
                InvokeSetControlEnable(true); 
            });
            bgWorker.RunWorkerAsync();
        }

        /// <summary>
        /// 繫結申報狀態
        /// </summary>
        private void BindApplyStateChild(TreeListNode treeNode, bool isLoading)
        {
            foreach (TreeListNode node in treeNode.Nodes)
            {
                if (isLoading)
                    node.StateImageIndex = (int)TreeNodeCheckImage.Loading;
                else
                {
                    string jgsyCode = node.GetValue("JGSY_CODE").ToString();
                    JGSYTreeService jgsyTreeService = new JGSYTreeService();
                    bool applyState = jgsyTreeService.GetApplyState(jgsyCode);
                    if (applyState)
                        node.StateImageIndex = (int)TreeNodeCheckImage.UnCheckedBranch;
                    else
                        node.StateImageIndex = (int)TreeNodeCheckImage.DisCheckedBranch;
                }
                BindApplyStateChild(node, isLoading);
            }
        }