c#DevExpress组件TreeList控件自己控制节点图标(三)

上面为绑定图片显示信息,以下为改变选择时候修改复选框状态:

        /// <summary>
        /// 设置单位树改变复选框状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>        
        private void treeListJgsyCommon_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                TreeListHitInfo hitInfo = treeListJgsyCommon.CalcHitInfo(new Point(e.X, e.Y));
                if (hitInfo.HitInfoType == HitInfoType.StateImage && btnExportData.Enabled)
                {
                    TreeListNode currTreeNode = hitInfo.Node;
                    switch ((TreeNodeCheckImage)currTreeNode.StateImageIndex)
                    {
                        case TreeNodeCheckImage.CheckedBranch:
                            currTreeNode.StateImageIndex = (int)TreeNodeCheckImage.UnCheckedBranch;
                            break;
                        case TreeNodeCheckImage.UnCheckedBranch:
                            currTreeNode.StateImageIndex = (int)TreeNodeCheckImage.CheckedBranch;
                            break;
                    }
                }
            }
        }


最终判断选择状态情况,如下:

/// <summary>
        /// 获取被选中的机构事业树
        /// </summary>
        List<JGSYTree> listJgsyTree = null;
          
        /// <summary>
        /// 导出上报数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExportData_Click(object sender, EventArgs e)
        {
            listJgsyTree = new List<JGSYTree>();
            foreach (TreeListNode node in treeListJgsyCommon.Nodes)
            {
                if (node.StateImageIndex == (int)TreeNodeCheckImage.CheckedBranch)
                    listJgsyTree.Add(treeListJgsyCommon.GetDataRecordByNode(node) as JGSYTree);
                if (node.HasChildren)
                    GetExportJgsy(node);                
            }
            if (listJgsyTree.Count == 0)
            {
                MessageBoxShow.Info("未选中导出数据的单位!");
                return;
            }            
            BackgroundWorker bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler((sender1, e1) =>
            {
                InvokeSetControlEnable(false);                
                string tempDBPath=string.Empty;
                //导出数据成功后用户将数据保存到本地
                if (StartExportData(listJgsyTree,out tempDBPath))
                {
                    SaveFileDialog saveFileDiaglog = new SaveFileDialog();
                    saveFileDiaglog.RestoreDirectory=true;
                    FileInfo file=new FileInfo(tempDBPath);
                    saveFileDiaglog.FileName=file.Name.Replace(".mdb","");
                    if (saveFileDiaglog.ShowDialog() == DialogResult.OK)
                    {
                        File.Copy(tempDBPath, saveFileDiaglog.FileName.Replace(".mdb", ""), true);                        
                    }
                    File.Delete(tempDBPath);
                }
                InvokeSetControlEnable(true);
            });
            bgWorker.RunWorkerAsync();
        }

        /// <summary>
        /// 获取选中的导出单位
        /// </summary>
        /// <param name="treeNode"></param>
        void GetExportJgsy(TreeListNode treeNode)
        {
            foreach (TreeListNode node in treeNode.Nodes)
            {
                if (node.StateImageIndex == (int)TreeNodeCheckImage.CheckedBranch)
                    listJgsyTree.Add(treeListJgsyCommon.GetDataRecordByNode(node) as JGSYTree);
                if (node.HasChildren)
                    GetExportJgsy(node);
            }
        }



 

你可能感兴趣的:(object,String,File,null)