Dev NavBarControl中嵌入TreeList并实现多级菜单

24 篇文章 1 订阅
/// <summary>
/// 初始化左侧树形结构
/// </summary>
private void InitNavBarControl()
{
    navBarTree.Groups.Clear();

    NavBarGroupControlContainer container = null;

    TreeList tv = null;

    KeyValuePair<string, string>[] namesAndCaptions = new KeyValuePair<string, string>[4] { new KeyValuePair<string, string>("navBar1", NAVBAR_CAE_PROCESS), new KeyValuePair<string, string>("navBar2", NAVBAR_TEMPLATE), new KeyValuePair<string, string>("navBar3", NAVBAR_WF), new KeyValuePair<string, string>("navBar4", NAVBAR_TOOL) };

    for (int i = 0; i < 4; i++)
    {
        container = new NavBarGroupControlContainer();

        navBarTree.Controls.Add(container);

        //添加Group
        NavBarGroup group = new NavBarGroup();
        group.Name = namesAndCaptions[i].Key;
        group.Caption = namesAndCaptions[i].Value;
        group.ControlContainer = container;
        group.Expanded = true;
        group.GroupClientHeight = 410;
        group.GroupStyle = NavBarGroupStyle.ControlContainer;
        navBarTree.Groups.Add(group);
    }

    //添加Item
    for (int i = 0; i < navBarTree.Groups.Count; i++)
    {
        //样式
        tv = new TreeList() { Name = "TreeList" + i , Caption = namesAndCaptions[i].Value };
        tv.Dock = DockStyle.Fill;
        tv.RowHeight = 25;
        tv.OptionsBehavior.Editable = false;
        tv.OptionsSelection.MultiSelect = false;
        tv.OptionsDragAndDrop.DragNodesMode = DragNodesMode.Single; //拖拽开关

        navBarTree.Controls[i].Controls.Add(tv); //必须在这个位置添加控件

        //注册事件
        tv.DragOver += tv_DragOver;
        tv.AfterFocusNode += tv_AfterFocusNode;

        var lstCAEDic = BLLSysSetting.BllSysDictionary.GetDicListByGroupCode(DictionaryEnum.CAEType);

        if (navBarTree.Groups[i].Name == namesAndCaptions[i].Key)
        {
            if (namesAndCaptions[i].Value == NAVBAR_CAE_PROCESS)
            {
                if (!lstCAEDic.HasValue())
                {
                    System.Diagnostics.Debug.WriteLine("frmSimWorkflow GetDicListByGroupCode error");
                    return;
                }

                tv.DataSource = lstCAEDic;
                tv.KeyFieldName = "id";

                tv.PopulateColumns();

                foreach (TreeListColumn col in tv.Columns)
                {
                    if (col.FieldName == nameof(SysDictionary.itemLabel))
                    {
                        col.Caption = "CAE过程名称";
                        col.Width = 150;
                    }
                    else
                    {
                        col.Visible = false;
                    }
                }
            }
            else if (namesAndCaptions[i].Value == NAVBAR_TEMPLATE)
            {
                if (!lstCAEDic.HasValue())
                {
                    System.Diagnostics.Debug.WriteLine("frmSimWorkflow GetDicListByGroupCode error");
                    return;
                }

                TreeListColumn colCode = new TreeListColumn() { Caption = "Code"};
                TreeListColumn colName = new TreeListColumn() { Caption = "名称"};

                tv.Columns.Add(colCode);
                tv.Columns.Add(colName);

                tv.Columns[0].Visible = false; //必须先添加列后设置Visible
                tv.Columns[1].Visible = true;

                tv.Refresh();
                
                foreach (var item in lstCAEDic)
                {
                    tv.BeginUnboundLoad();

                    TreeListNode node = tv.AppendNode(item, -1);

                    node.Tag = item;

                    node.SetValue(0, item.itemCode);
                    node.SetValue(1, item.itemLabel);

                    tv.EndUnboundLoad();
                }
            }
            else if (namesAndCaptions[i].Value == NAVBAR_WF)
            {
                var lstDic = BLLSimFlow.BllSimWorkflow.GetListByWhere(new SimWorkflow() { flagStatus = 0 });

                tv.DataSource = lstDic;
                tv.KeyFieldName = "id";

                tv.PopulateColumns();

                foreach (TreeListColumn col in tv.Columns)
                {
                    if (col.FieldName == nameof(SimWorkflow.flowName))
                    {
                        col.Caption = "流程名称";
                        col.Width = 150;
                    }
                    else
                    {
                        col.Visible = false;
                    }
                }
            }
            else if (namesAndCaptions[i].Value == NAVBAR_TOOL)
            {
                var lstDic = BLLSimTools.BllSimTool.GetListByWhere(new SimTool { flagStatus = 0 });

                tv.DataSource = lstDic;
                tv.KeyFieldName = "id";

                tv.PopulateColumns();

                foreach (TreeListColumn col in tv.Columns)
                {
                    if (col.FieldName == nameof(SimTool.simToolName))
                    {
                        col.Caption = "工具名称";
                        col.Width = 150;
                    }
                    else
                    {
                        col.Visible = false;
                    }
                }
            }
            //取消默认焦点
            tv.FocusedNode = null;
            tv.SetFocusedNode(null);
        }
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值