This is a migrated thread and some comments may be shown as answers.

Filtering for self-reference hierarchy in gridview

1 Answer 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
thuy
Top achievements
Rank 1
thuy asked on 02 Jul 2014, 04:52 AM
Hello,



I have displayed in datagridview with data in self-reference hierarchy. For example, I have data in the gridview ad the below:

Node1

    Node 1.1

    Node 1.2

        Node 1.2.1

        Node 1.2.2

            Node 1.2.2.1

.....



When I click filtering icon in the header column. The filtering dialog
doesn't display the same structure in the datagridview. It just displays
as the below in filtering dialog.

All

    Node1

    Node 1.1

    Node 1.2



I expect the filtering dialog should display as same as the
datagridview. Please show me how to do. I also attach the screenshot for
more detail

Thannks

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Jul 2014, 03:46 PM
Hello Thuy,

Thank you for writing.

I confirm that the missing items for deeper levels in self-reference hierarchy is an issue in our RadGridView. I have logged it in our Feedback Portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - Feedback Item.

I have also updated your Telerik points.

Currently, the possible solution is to customize the filter popup via the RadGridView.FilterPopupInitialized event and the RadListFilterPopup.PopupOpened event. Thus, you can add the missing values:
DataTable dt = new DataTable();
 
public Form1()
{
    InitializeComponent();
 
    this.radGridView1.EnableFiltering = true;
    this.radGridView1.ShowHeaderCellButtons = true;
 
    this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "ID", "ParentID");
     
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("Title", typeof(string));
    dt.Columns.Add("ParentID", typeof(int));
 
    for (int i = 1; i <= 5; i++)
    {
        dt.Rows.Add(i, "Parent." + i, 0);
    }
 
    Random rand = new Random();
    for (int i = 6; i < 20; i++)
    {
        dt.Rows.Add(i, "Child." + i, rand.Next(1, 6)); 
    }
 
    for (int i = 20; i < 40; i++)
    {
        dt.Rows.Add(i, "SubChild." + i, rand.Next(6, 20)); 
    }
 
    this.radGridView1.DataSource = dt;
    this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
 
string columnName = string.Empty;
private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
    RadListFilterPopup popUp = e.FilterPopup as RadListFilterPopup;
    columnName = e.Column.FieldName;
    if (popUp != null)
    {
        popUp.PopupOpened -= popUp_PopupOpened;
        popUp.PopupOpened += popUp_PopupOpened;
    }
}
 
private void popUp_PopupOpened(object sender, EventArgs args)
{
    RadListFilterPopup popUp = sender as RadListFilterPopup;
    popUp.MenuTreeElement.TreeView.Nodes.Last().Nodes.Clear();
     
    foreach (DataRow row in dt.Rows)
    {
        RadTreeNode node = new RadTreeNode(row[columnName].ToString());
        node.Checked = true;
        popUp.MenuTreeElement.TreeView.Nodes.Last().Nodes.Add(node);
    }
   
 
}

Note that this is just a sample approach, which demonstrates the idea and it may not cover all possible cases. Feel free to modify it in a way which suits your scenario best.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
thuy
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or