zl程序教程

您现在的位置是:首页 >  后端

当前栏目

带线的无限级下拉树列表

列表 无限
2023-09-14 08:59:37 时间

好多年没写文章了
这里就分享点自己原创的一点破代码,效果如图下:
r_%7BDB83491B-1991-48D4-9A9B-69704E20B45
本人的提供的代码如下:

None.gifusing System;
None.gifusing System.Collections.Generic;
None.gifusing System.Text;
None.gifusing System.Web.UI.WebControls;
None.gif
None.gifnamespace Interface.Common
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    public interface IDropDownTree : IDisposable
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 返回Dictionary里分别对应ID,文本,如果没有子节点返回null
InBlock.gif        ///  /summary
InBlock.gif        ///  param name="parentID" 父节点ID /param
ExpandedSubBlockEnd.gif        ///  returns /returns
InBlock.gif        Dictionary string, string  GetChildCategory(string parentID);
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 代码里写return new Interface.Common.DropDownTree(this);
ExpandedSubBlockEnd.gif        ///  /summary
InBlock.gif        DropDownTree DropDownTree
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            get;
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif    }
InBlock.gif    public sealed class DropDownTree
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        IDropDownTree _DropDownTree;
InBlock.gif        public DropDownTree(IDropDownTree dropDownTree)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            _DropDownTree = dropDownTree;
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 用于树的前缀
InBlock.gif        ///  /summary
InBlock.gif        ///  param name="IsLast" 是否是同级节点中的最后一个 /param
InBlock.gif        ///  param name="HasChild" 本节点是否拥有子节点 /param
InBlock.gif        ///  param name="ParentString" 父节点前缀符号 /param
ExpandedSubBlockEnd.gif        ///  returns 本节点的前缀 /returns
InBlock.gif        private string GetPreFix(bool isLast, bool hasChild, string parentString)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string result = string.Empty;
InBlock.gif            if (!string.IsNullOrEmpty(parentString))
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                parentString = parentString.Remove(parentString.Length - 1).Replace("├", "│").Replace("└", " ");
InBlock.gif                result += parentString;
ExpandedSubBlockEnd.gif            }
InBlock.gif            if (isLast)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                result += "└";
ExpandedSubBlockEnd.gif            }
InBlock.gif            else
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                result += "├";
ExpandedSubBlockEnd.gif            }
InBlock.gif            if (hasChild)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                result += "┬";
ExpandedSubBlockEnd.gif            }
InBlock.gif            else
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                result += "─";
ExpandedSubBlockEnd.gif            }
InBlock.gif            return result;
ExpandedSubBlockEnd.gif        }
ContractedSubBlock.gifExpandedSubBlockStart.gif        绑定下拉菜单#region 绑定下拉菜单
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 绑定连动级的下拉菜单
InBlock.gif        ///  /summary
InBlock.gif        ///  param name="ddlGoodsType" 传进一个被绑定的DropDownList /param
InBlock.gif        ///  param name="removeID" 被排除绑定的节点ID /param
ExpandedSubBlockEnd.gif        ///  param name="AutoDispose" 是否自动释放 /param
InBlock.gif        public void BindToDropDownList(DropDownList ddlGoodsType, string removeID,string parentID, bool autoDispose)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (ddlGoodsType != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ListItem listItem = null;
InBlock.gif                string currentID = parentID;//根节点/父ID
InBlock.gif                string currentSign = string.Empty;//当前节点符号;
InBlock.gif                string parrentSign = string.Empty; //父节点符号;
InBlock.gif                bool HasChild = true;//是否有子
InBlock.gif                Queue string  parentKeyList = new Queue string //存 有子节点的 节点ID
InBlock.gif                Queue string  parentSignList = new Queue string //对应节点ID的前缀符号
InBlock.gif                int itemIndexOf = 0;//父节点所在的位置
InBlock.gif                while (HasChild)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    int lastOneCount = 1;//用于计算在同级别中是否最后一个
InBlock.gif                    Dictionary string, string  childList = _DropDownTree.GetChildCategory(currentID);// 得到子节点列表
InBlock.gif                    if (childList != null   childList.Count   0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        if (!string.IsNullOrEmpty(removeID)   childList.ContainsKey(removeID))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
InBlock.gif                            childList.Remove(removeID);
ExpandedSubBlockEnd.gif                        }
InBlock.gif                        foreach (KeyValuePair string, string  entry in childList)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
InBlock.gif                            if (_DropDownTree.GetChildCategory(entry.Key) != null)//存在子
ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
InBlock.gif                                currentSign = GetPreFix(lastOneCount == childList.Count, true, parrentSign);
InBlock.gif                                listItem = new ListItem(currentSign + entry.Value, entry.Key);
InBlock.gif
InBlock.gif                                parentKeyList.Enqueue(entry.Key);//当前的节点ID
InBlock.gif                                parentSignList.Enqueue(currentSign);//当前的节点符号
ExpandedSubBlockEnd.gif                            }
InBlock.gif                            else//不存在子
ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
InBlock.gif                                currentSign = GetPreFix(lastOneCount == childList.Count, false, parrentSign);
InBlock.gif                                listItem = new ListItem(currentSign + entry.Value, entry.Key);
ExpandedSubBlockEnd.gif                            }
InBlock.gif                            if (ddlGoodsType.Items.Count != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
InBlock.gif                                itemIndexOf = string.IsNullOrEmpty(currentID) ? itemIndexOf + 1 : ddlGoodsType.Items.IndexOf(ddlGoodsType.Items.FindByValue(currentID)) + lastOneCount;
ExpandedSubBlockEnd.gif                            }
InBlock.gif                            ddlGoodsType.Items.Insert(itemIndexOf, listItem);//添加子节点
InBlock.gif                            lastOneCount++;
ExpandedSubBlockEnd.gif                        }
InBlock.gif                        if (parentKeyList.Count   0)//存在子节点时
ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
InBlock.gif                            currentID = parentKeyList.Dequeue();
InBlock.gif                            parrentSign = parentSignList.Dequeue();
ExpandedSubBlockEnd.gif                        }
InBlock.gif                        else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
InBlock.gif                            HasChild = false;
ExpandedSubBlockEnd.gif                        }
ExpandedSubBlockEnd.gif                    }
InBlock.gif                    else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        break;
ExpandedSubBlockEnd.gif                    }
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif                }
InBlock.gif                if (autoDispose)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    _DropDownTree.Dispose();
ExpandedSubBlockEnd.gif                }
InBlock.gif
ExpandedSubBlockEnd.gif            }
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 绑定连动级的下拉菜单
InBlock.gif        ///  /summary
ExpandedSubBlockEnd.gif        ///  param name="ddlGoodsType" 传进一个被绑定的DropDownList /param
InBlock.gif        public void BindToDropDownList(DropDownList ddlGoodsType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            BindToDropDownList(ddlGoodsType, string.Empty,null, true);
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 绑定连动级的下拉菜单
InBlock.gif        ///  /summary
InBlock.gif        ///  param name="ddlGoodsType" 传进一个被绑定的DropDownList /param
ExpandedSubBlockEnd.gif        ///  param name="removeID" 被排除的ID /param
InBlock.gif        public void BindToDropDownList(DropDownList ddlGoodsType, string removeID)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            BindToDropDownList(ddlGoodsType, removeID,null, true);
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**////  summary
InBlock.gif        /// 绑定连动级的下拉菜单
InBlock.gif        ///  /summary
InBlock.gif        ///  param name="ddlGoodsType" 传进一个被绑定的DropDownList /param
InBlock.gif        ///  param name="removeID" 被排除的ID,若没有,传null /param
ExpandedSubBlockEnd.gif        ///  param name="parentID" 起始父ID /param
InBlock.gif        public void BindToDropDownList(DropDownList ddlGoodsType, string removeID,string parentID)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            BindToDropDownList(ddlGoodsType, removeID,parentID, true);
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif        #endregion
ExpandedSubBlockEnd.gif    }
ExpandedBlockEnd.gif}

调用方法很简单:
1.继承自IDropDownTree接口
2.实现3个接口方法

实现接口代码示例[Dispose方法自己实现],最主要的是自己实现获得子级的方法
ContractedBlock.gifExpandedBlockStart.gif IDropDownTree 成员#region IDropDownTree 成员
InBlock.gif
InBlock.gif        public Dictionary string, string  GetChildCategory(string parentID)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string where = "ParentID=" + parentID + "";
InBlock.gif            if (string.IsNullOrEmpty(parentID))
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                where = "ParentID is null or ParentID=" + Guid.Empty + "";
ExpandedSubBlockEnd.gif            }
InBlock.gif            List GoodsCategoryBean  _GoodsCategoryList = SelectList(0, where, string.Empty, false);
InBlock.gif            if (_GoodsCategoryList != null   _GoodsCategoryList.Count   0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                Dictionary string, string  categoryList = new Dictionary string, string
InBlock.gif                for (int i = 0; i   _GoodsCategoryList.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    categoryList.Add(_GoodsCategoryList[i].ID.ToString(), _GoodsCategoryList[i].GategoryName);
ExpandedSubBlockEnd.gif                }
InBlock.gif                return categoryList;
ExpandedSubBlockEnd.gif            }
InBlock.gif            return null;
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        public Interface.Common.DropDownTree DropDownTree
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gif{ return new Interface.Common.DropDownTree(this); }
ExpandedSubBlockEnd.gif        }
InBlock.gif
ExpandedBlockEnd.gif        #endregion 页面调用代码: 类名.DropDownTree.BindToDropDownList(下拉控件ID);

希望对大伙有点帮助....
一.浮动布局 1.先让固定宽度的div浮动!使其脱离文档流。 2.margin-left的值等于固定div的宽度相等。
HorizontalScrollView包裹RecyclerView,使用StaggeredGridLayoutManager均分网格形成表格状列表,不固定列,每次刷新数据列位置异常错乱变动问题 问题描述:用Horizon...