本文整理汇总了C#中TreeList.FindNodeByKeyID方法的典型用法代码示例。如果您正苦于以下问题:C# TreeList.FindNodeByKeyID方法的具体用法?C# TreeList.FindNodeByKeyID怎么用?C# TreeList.FindNodeByKeyID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeList
的用法示例。
在下文中一共展示了TreeList.FindNodeByKeyID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 idfld, string pidfld, string tagformat)
{
//检查传入参数
if (null == trv || null == dr || string.IsNullOrEmpty(txtfld) || string.IsNullOrEmpty(idfld))
return null;
DataTable tab = dr.Table;
if (!tab.Columns.Contains(txtfld) || !tab.Columns.Contains(idfld))
return null;
if (!string.IsNullOrEmpty(pidfld) && !tab.Columns.Contains(pidfld))
return null;
if (DBNull.Value == dr[idfld])
return null;
//没有节点则增加,递归处理父节点
DataRow pdr = null;
TreeListNode trn = null, ptrn = null;
//有则直接返回
trn = trv.FindNodeByKeyID(Convert.ToString(dr[idfld]));
if (null != trn)
return trn;
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, idfld, pidfld, tagformat);
//附加tag标签值
if (!string.IsNullOrEmpty(tagformat))
{
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);
}
}
//添加节点
if (null == ptrn)
{
trn = trv.AppendNode(new object[] { Convert.ToString(dr[txtfld]), Convert.ToString(dr[idfld]) }, null, tagformat);
trn.ImageIndex = 1;
trn.SelectImageIndex = 1;
}
else
{
trn = trv.AppendNode(new object[] { Convert.ToString(dr[txtfld]), Convert.ToString(dr[idfld]) }, ptrn, tagformat);
trn.ImageIndex = 2;
trn.SelectImageIndex = 2;
}
return trn;
}