本文整理汇总了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;
}
示例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);
}
}
}