Completed
Last Updated: 14 Nov 2014 13:24 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 20 Jun 2014 07:14
Category: TreeView
Type: Bug Report
1
FIX. RadTreeView - FilterDescriptor.PropertyName is not taken into consideration when filtering a bound RadTreeView
To reproduce: use the following code

public class Item
{
    public int Id { get; set; }

    public string Title { get; set; }

    public string Tag { get; set; }

    public Item(int id, string title, string tag)
    {
        this.Id = id;
        this.Title = title;
        this.Tag = tag;
    }
}

public Form1()
{
    InitializeComponent();

    List<Item> items = new List<Item>();
    items.Add(new Item(1,"a1","x1"));
    items.Add(new Item(2,"a2","x2"));
    items.Add(new Item(3,"a3","x3"));
    items.Add(new Item(4,"b1","y1"));
    items.Add(new Item(5,"b2","y2"));
    items.Add(new Item(6,"b3","y3"));
    this.radTreeView1.DataSource = items;
    this.radTreeView1.DisplayMember = "Title";
    this.radTreeView1.ValueMember = "Id";
   
    radTreeView1.FilterDescriptors.Add(new FilterDescriptor("Tag", FilterOperator.Contains, "y"));
}

Workaround: use custom filtering:
public Form1()
{
    InitializeComponent();

    List<Item> items = new List<Item>();
    items.Add(new Item(1,"a1","x1"));
    items.Add(new Item(2,"a2","x2"));
    items.Add(new Item(3,"a3","x3"));
    items.Add(new Item(4,"b1","y1"));
    items.Add(new Item(5,"b2","y2"));
    items.Add(new Item(6,"b3","y3"));
    this.radTreeView1.DataSource = items;
    this.radTreeView1.DisplayMember = "Title";
    this.radTreeView1.ValueMember = "Id";
   
    radTreeView1.FilterDescriptors.Add(new FilterDescriptor("Tag", FilterOperator.Contains, "y")); 
    radTreeView1.TreeViewElement.FilterPredicate = FilterNode;
}

public class Item
{
    public int Id { get; set; }

    public string Title { get; set; }

    public string Tag { get; set; }

    public Item(int id, string title, string tag)
    {
        this.Id = id;
        this.Title = title;
        this.Tag = tag;
    }
}

private bool FilterNode(RadTreeNode node)
{
    Item item = node.DataBoundItem as Item;
  
    if (item != null && radTreeView1.FilterDescriptors.Count > 0)
    { 
        FilterDescriptor fd = radTreeView1.FilterDescriptors[0];
        var propertyValue = item.GetType().GetProperty(fd.PropertyName,
            BindingFlags.Public | BindingFlags.Instance).GetValue(item, null);
        if (propertyValue.ToString().Contains(fd.Value.ToString()))
        {
            return true;
        }
        return false;
    }

    return false;
}
0 comments