当前位置: 首页>>代码示例>>C#>>正文


C# TreeList.FindNodeByFieldValue方法代码示例

本文整理汇总了C#中TreeList.FindNodeByFieldValue方法的典型用法代码示例。如果您正苦于以下问题:C# TreeList.FindNodeByFieldValue方法的具体用法?C# TreeList.FindNodeByFieldValue怎么用?C# TreeList.FindNodeByFieldValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeList的用法示例。


在下文中一共展示了TreeList.FindNodeByFieldValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetTreeNode

        /// <summary>
        /// 根据数据记录设置树节点,有则直接返回无则添加节点
        /// </summary>
        /// <param name="trv">树控件</param>
        /// <param name="dr">数据记录</param>
        /// <param name="txtfld">文本字段</param>
        /// <param name="cardNo">卡号</param>
        /// <param name="idfld">键值字段</param>
        /// <param name="pidfld">父键字段</param>
        /// <param name="tagformat">附加tag标签属性值格式:对其中{字段名称}替换具体值,没有该字段则不替换</param>
        /// <returns>返回数据记录对应的树节点</returns>
        public static TreeListNode SetTreeNode(TreeList trv, DataRow dr, string txtfld,string cardNo, string idfld, string pidfld, string tagformat)
        {
            //检查传入参数
            if (null == trv || null == dr || string.IsNullOrEmpty(txtfld) || string.IsNullOrEmpty(idfld) || string.IsNullOrEmpty(cardNo))
                return null;
            DataTable tab = dr.Table;
            if (!tab.Columns.Contains(txtfld) || !tab.Columns.Contains(idfld) || !tab.Columns.Contains(cardNo))
                return null;
            if (!string.IsNullOrEmpty(pidfld) && !tab.Columns.Contains(pidfld))
                return null;
            if (DBNull.Value == dr[idfld])
                return null;

            //有则直接返回
            string key = Convert.ToString(dr[idfld]);
            //   TreeNode[] trns = trv.Nodes.Find(key, true);

            foreach (TreeListNode nd in trv.Nodes)
            {
                TreeListNode trns = trv.FindNodeByFieldValue("id", dr["id"].ToString());
                if (trns != null)
                {
                    return trns;
                }
            }

            //没有节点则增加,递归处理父节点
            DataRow pdr = null;
            TreeListNode trn = null, ptrn = null;
            if (!string.IsNullOrEmpty(pidfld) && DBNull.Value != dr[pidfld])
            {
                object pobj = dr[pidfld];
                for (int i = 0, len = tab.Rows.Count; i < len; i++)
                {
                    if (!pobj.Equals(tab.Rows[i][idfld]))
                        continue;
                    pdr = tab.Rows[i];
                    break;
                }
            }
            if (null != pdr)
                ptrn = BindManager.SetTreeNode(trv, pdr, txtfld, cardNo,idfld, pidfld, tagformat);
            if (null == ptrn)
            {
                if (dr[cardNo].ToString() != string.Empty)
                {
                    trn = trv.AppendNode(new object[] { Convert.ToString(dr[txtfld]) + "(" + Convert.ToString(dr[cardNo]) + ")", Convert.ToString(dr[idfld]) }, null, key);
                }
                else
                {
                    trn = trv.AppendNode(new object[] { Convert.ToString(dr[txtfld]), Convert.ToString(dr[idfld]) }, null, key);
                }
                trn.ImageIndex = 1;
                trn.SelectImageIndex =1;
            }
            else
            {
                if (dr[cardNo].ToString() != string.Empty)
                {

                    trn = trv.AppendNode(new object[] { Convert.ToString(dr[txtfld]) + "(" + Convert.ToString(dr[cardNo]) + ")", Convert.ToString(dr[idfld]) }, ptrn, key);
                }
                else
                {
                    trn = trv.AppendNode(new object[] { Convert.ToString(dr[txtfld]), Convert.ToString(dr[idfld]) }, ptrn, key);
                }
                trn.ImageIndex = 2;
                trn.SelectImageIndex = 2;
            }

            //附加tag标签值
            if (string.IsNullOrEmpty(tagformat))
                return trn;
            DataColumnCollection cols = tab.Columns;
            foreach (DataColumn col in cols)
            {
                string fld = col.ColumnName;
                string val = "";
                if (DBNull.Value != dr[fld])
                    val = Convert.ToString(dr[fld]);
                tagformat = tagformat.Replace("{" + fld + "}", val);
            }
            trn.Tag = tagformat;
            return trn;
        }
开发者ID:thisisvoa,项目名称:GranityApp2.5,代码行数:96,代码来源:BindManager.cs

示例2: UpdateMenuTreeList

 public static void UpdateMenuTreeList(TreeList treeList, ChoiceActionItem parentItem)
 {
     if (treeList == null)
     {
         throw new ArgumentNullException("treeList");
     }
     object obj = null;
     if (treeList.FocusedNode != null)
     {
         obj = treeList.FocusedNode.GetValue(TreeListHelper._treeList.Columns[1].FieldName);
     }
     TreeListHelper._treeList = treeList;
     TreeListHelper._imageList = (ImageList)treeList.SelectImageList;
     List<object> list = new List<object>();
     TreeListHelper.TreeListExpanded(TreeListHelper._treeList.Nodes, list);
     treeList.ClearNodes();
     TreeListHelper.CreateMenu(null, parentItem);
     foreach (object current in list)
     {
         TreeListNode treeListNode;
         if ((treeListNode = TreeListHelper._treeList.FindNodeByFieldValue(TreeListHelper._treeList.Columns[1].FieldName, current)) != null)
         {
             treeListNode.Expanded = true;
         }
     }
     if (obj != null)
     {
         TreeListNode treeListNode2 = treeList.FindNodeByFieldValue(TreeListHelper._treeList.Columns[1].FieldName, obj);
         if (treeListNode2 != null)
         {
             treeList.SetFocusedNode(treeListNode2);
         }
     }
 }
开发者ID:LSTANCZYK,项目名称:devexpress_xaf_aurum,代码行数:34,代码来源:TreeListMenusControl.cs


注:本文中的TreeList.FindNodeByFieldValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。