var node = treeList1.AppendNode("", null);
node.SetValue(treeListColumn1, obj1);
node.Tag = obj2;
private void treeListMaster_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e)
{
var index = e.Node.GetValue("IMAGEINDEX");
if (index.ToString() != string.Empty)
{
e.SelectImageIndex = Convert.ToInt32(index);
}
}
private void labelControl1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
labelControl1.Appearance.ImageIndex = 1;//换为打开的垃圾桶
}
private void labelControl1_DragDrop(object sender, DragEventArgs e)
{
//这里执行删除节点操作
DeleteNode();
labelControl1.Appearance.ImageIndex = 0;//换为关闭的垃圾桶
}
private void labelControl1_DragLeave(object sender, EventArgs e)
{
labelControl1.Appearance.ImageIndex = 0;//换位关闭的垃圾桶
}
树内部拖曳,移动或节点排序也可以在DragDrop中操作
treeList1.SetNodeIndex(dragnode, treeList1.GetNodeIndex(targetnode));
class FilterNodeOperation : TreeListOperation
{
string pattern;
public FilterNodeOperation(string _pattern)
{
pattern = _pattern;
}
public override void Execute(TreeListNode node)
{
if (NodeContainsPattern(node, pattern))
{
node.Visible = true;
//if (node.ParentNode != null)
// node.ParentNode.Visible = true;
//必须要递归查找其父节点全部设置为可见
var pNode = node.ParentNode;
while (pNode != null)
{
pNode.Visible = true;
pNode = pNode.ParentNode;
}
}
else
node.Visible = false;
}
bool NodeContainsPattern(TreeListNode node, string pattern)
{
foreach (TreeListColumn col in node.TreeList.VisibleColumns)
{
if (node.GetDisplayText(col).Contains(pattern))
return true;
}
return false;
}
}
//在ButtonEdit的ButtonClick事件中执行这个Operation:
private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
var operation = new FilterNodeOperation(buttonEdit1.EditValue != null ? buttonEdit1.EditValue.ToString() : "");
treeListMaster.NodesIterator.DoOperation(operation);
}