Self-referencing Hierarchy

12 posts, 0 answers
  1. Robert
    Robert avatar
    6 posts
    Member since:
    Jun 2009

    Posted 13 Oct 2009 Link to this post

    Hi,

    I recently read that self-referencing hierarchy is now supported by the radGridView.  Unfortunately, I have been unable to locate any demos, tutorials, or sample code to look at.  Is this information available?

    Here is my current code that I'm working with:

    private void SetupElementsGrid()  
    {  
        radGvElements.Columns.Clear();  
        radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ElementID"));  
        radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ProtocolTemplateID"));  
        radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ParentElementID"));  
        radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ElementNumber"));  
        radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ElementDesc"));  
     
        radGvElements.Columns["ElementID"].IsVisible = false;  
        radGvElements.Columns["ProtocolTemplateID"].IsVisible = false;  
        radGvElements.Columns["ParentElementID"].IsVisible = false;  
     
        radGvElements.Columns["ElementNumber"].HeaderText = "Element Number";  
        radGvElements.Columns["ElementDesc"].HeaderText = "Element Description";  
     
        radGvElements.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;  
     
        GridViewTemplate childTemplate = new GridViewTemplate();     
        childTemplate.Columns.Add(new GridViewTextBoxColumn("ElementID"));  
        childTemplate.Columns.Add(new GridViewTextBoxColumn("ProtocolTemplateID"));  
        childTemplate.Columns.Add(new GridViewTextBoxColumn("ParentElementID"));  
        childTemplate.Columns.Add(new GridViewTextBoxColumn("ElementNumber"));  
        childTemplate.Columns.Add(new GridViewTextBoxColumn("ElementDesc"));  
     
        //childTemplate.Columns["ElementID"].IsVisible = false;  
        //childTemplate.Columns["ProtocolTemplateID"].IsVisible = false;  
        //childTemplate.Columns["ParentElementID"].IsVisible = false;  
     
        //childTemplate.Columns["ElementNumber"].HeaderText = "Element Number";  
        //childTemplate.Columns["ElementDesc"].HeaderText = "Element Description";  
     
        childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;  
          
        if(radGvElements.MasterGridViewTemplate.ChildGridViewTemplates.Count == 0)  
        {                     
            radGvElements.MasterGridViewTemplate.ChildGridViewTemplates.Add(childTemplate);  
        }  
          
        GridViewRelation relation = new GridViewRelation(radGvElements.MasterGridViewTemplate);  
        relation.ChildTemplate = childTemplate;  
        relation.RelationName = "ParentChild";  
        relation.ParentColumnNames.Add("ElementID");  
        relation.ChildColumnNames.Add("ParentElementID");  
        radGvElements.Relations.Add(relation);  
     
        ProtocolTemplate = (ProtocolTemplate)ProtocolTemplatesBindingSource.CurrencyManager.List[ProtocolTemplatesBindingSource.CurrencyManager.Position];  
        ElementsBindingSource.DataSource = ProtocolTemplate.Elements;  
        radGvElements.DataSource = ElementsBindingSource;  
                      
        radGvElements.DataSource = ElementsBindingSource;  
        childTemplate.DataSource = ElementsBindingSource;  

    Sample data would look like this:

    ElementID -- ProtocolTemplateID -- ParentElementID -- ElementNumber -- ElementDesc
    1 -- 1 -- 1 -- 1.0 -- ParentLevel1
    2 -- 1 -- 1 -- 1.1 -- ChildLevel1
    3 -- 1 -- 1 -- 1.2 -- ChildLevel2
    4 -- 1 -- 4 -- 2.0 -- ParentLevel2

    With my current code, this displays as:

    Row 1
    -- Row1
    -- Row2
    -- Row3
    Row 2
    Row 3
    Row 4
    -- Row 4

    It should be:

    Row 1
    -- Row 2
    -- Row 3
    Row 4

    Also, another problem is with the portion of code I have commented out.  This code causes a NullReferenceException error to be thrown and I don't know why.

     

    If anyone could help me out with the above code, or even point me in the direction of some reading material, I would be very grateful.

    Thanks,

    Robert

  2. David Kozikowski
    David Kozikowski avatar
    3 posts
    Member since:
    Sep 2009

    Posted 14 Oct 2009 Link to this post

    Yes I too am having a hard time making this work. I just bought the .net collection. I’m using the RADGridView. I want to be able to show a simple Invoice  - > InvoiceLine Item relationship

     

    I would expect to be able to drop a RADGridView on a form set the data source to the dataset that has the relation I’m after. (A dataset that contains the 2 tables Invoice and InvoiceLineItem related in SQL by a Foreign Key constraint in the InvoiceLineItem  )  Set Auto Generate Hierarchy to true , hit F5 and see the form come up with data. (before.jpg)It all work this way but I done see the child Data nothing and when I hit one of the child tabs I get an out or range error. (after.jpg)

     The only data in the DB is 1 Invoice that has 2 line Line Items (sqltables.jpg)

    Telerick Please provide a "how to" demo on this as it was a big selling point.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 16 Oct 2009 Link to this post

    Hello Robert and David,

    Currently, RadGridView control does not support self-reference hierarchy, however this feature is in development and will be available very soon.

    David, please verify you relations in the generated typed DataSet by Visual Studio. The generated hierarchy is strange in your scenario, it contains two InvoiceLineItem child templates. Please review the hierarchy section in our Demo application.

    All the best,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. David Kozikowski
    David Kozikowski avatar
    3 posts
    Member since:
    Sep 2009

    Posted 16 Oct 2009 Link to this post

  6. Hierarchy (Master-Detail Layout) with Tabbed Child View

    Presentation of related DataSets is a breeze with the supported hierarchical table structures, regardless of the grid mode (bound, unbound, or virtual). You can build self-referencing hierarchy from a single table in the datasource by specifying relations within the same level. Each hierarchical view comes with all editing features such as end-user sorting, filtering, aggregates, integrated cell editors, etc.

    RadGridView for WinForms from Telerik - Hierarchy Support

    In addition to the standard Hierarchy View, GridView for Windows Forms offers a Tabbed Child View which shows master-detail (one to many) relations in a tabbed layout while in hierarchy mode:
     
    RadGridView for WinForms - Detail Tabs

  7. IT's says you can do self-reference hierarchy right is the doc. My relations are defined like the sqltables.jpg it's a simple.

    What I'm looking for is a demo example and I can't find one please be more precise on where to look Like WinForm sample 5 or some thing. I would also think this should be in the help docs called "Using  Hierarchy (Master-Detail Layout) with Tabbed Child View" or something. I just bought 5 licences because of this feature, now you saying that it's not implemented?

     

  • Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 20 Oct 2009 Link to this post

    Hi David Kozikowski,

    In the current edition of RadGridView, you can build self-reference, but you have to add child templates manually and bind to the same data source many times.

    Full featured self-reference is the automatic generation of hierarchy from the desired data source if a property like IsSelfReference is set for the extended Relation object. We currently work on this new functionality and it will be available very soon but after Q3 2009.

    Sincerely yours,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  • Robert
    Robert avatar
    6 posts
    Member since:
    Jun 2009

    Posted 20 Oct 2009 Link to this post

    Hi Julian,

    "In the current edition of RadGridView, you can build self-reference, but you have to add child templates manually and bind to the same data source many times."

    As you can see from my original sample code, I am building and adding the child templates manually and have bound to the same data source twice, yet this still does not work.

    Am I doing something wrong?  Can you please review my code and see what I'm missing?  Any assistance would be greatly appreciated...

    Thanks,

    Robert
  • Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 23 Oct 2009 Link to this post

    Hi Robert,

    Sorry for the introduced inconvenience.

    In order to make self-reference scenario work in this situation, you must also filter the data by its parent/child key. The data source for MasterGridVewTemplate must contain all rows filtered by 'ParentId == null'. For this child template, rows must be filtered by 'ParentId != null". In general, this introduce more lines of code and complexity. To avoid this and make the process simpler, we currently implement a new mechanism where you will only need to set the DataSource of RadGridView and add just one self-reference relation.

    All the best,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  • Paul
    Paul avatar
    35 posts
    Member since:
    Jan 2014

    Posted 25 Apr 2014 in reply to Julian Benkov Link to this post

    Are there any examples on the Telerik site on how to filter a self-reference grid?

    Thanks

    Paul
  • Dess
    Admin
    Dess avatar
    1601 posts

    Posted 30 Apr 2014 Link to this post

    Hello Paul,

    Thank you for writing.

    In our Demo Application > GridView > Filtering section there are several examples related to data filtering in grid. You can find an example about self-reference in  Demo Application >> GridView >> Hierarchy section. Both of the examples can be combined to enable filtering in self-reference hierarchy:
    public Form1()
    {
        InitializeComponent();
     
        this.radGridView1.Columns.Add("Id");
        this.radGridView1.Columns.Add("Name");
        this.radGridView1.Columns.Add("ParentFolderId");
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.EnableFiltering = true;
     
        this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "Id", "ParentFolderId");
     
        for (int i = 1; i <= 7; i++)
        {
            radGridView1.Rows.Add(i, "Parent" + i, 0);
            for (int j = 8; j <= 15; j++)
            {
                dynamic childIndex = ((i - 1) * 9 + j + i);
                radGridView1.Rows.Add(childIndex, "Child" + childIndex, i);
            }
        }
    }

    Please have a look at the attached gif file, illustrating better the available functionality. 

    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.
     
  • fariba
    fariba avatar
    21 posts
    Member since:
    May 2014

    Posted 20 Apr in reply to Dess Link to this post

    Hi,
    Dear Dess,

    I am using Self-referencing Hierarchy radgridview and I want to have customize sample search on it
    I have text-box on the form and I want to find entered  text in both parents and children ,the search starts from the selected row to down (Like search in browser's page)

    Is there any similar sample which shows me how can I implement this?I search a lot but I could not find any suitable sample.

     

    Thanks

    Fariba

  • fariba
    fariba avatar
    21 posts
    Member since:
    May 2014

    Posted 20 Apr in reply to fariba Link to this post

    I just find below code which only search in one level

        private void radTextBox1_TextChanged(object sender, EventArgs e)
            {
                if (radGridView1.SelectedRows != null && radGridView1.SelectedRows.Count > 0 && radTextBox1.Text.Trim() != string.Empty)
                {
                    GridViewHierarchyRowInfo hierarchyRow = radGridView1.SelectedRows[0] as GridViewHierarchyRowInfo;
                    if (hierarchyRow != null)
                    {
                        IterateChildRows(hierarchyRow);
                    }

                }
            }

     

     

            private void IterateChildRows(GridViewHierarchyRowInfo rowInfo)
            {
                GridViewInfo currentView = rowInfo.ActiveView;
                foreach (GridViewInfo view in rowInfo.Views)
                {
                    rowInfo.ActiveView = view;
                    foreach (GridViewRowInfo row in rowInfo.ChildRows)
                    {
                        if (row.Cells["name"].Value.ToString().Contains(radTextBox1.Text.Trim()))
                        {
                            radGridView1.CurrentRow = row;
                            return;
                        }
                        GridViewHierarchyRowInfo hierarchyRow = row as GridViewHierarchyRowInfo;
                        if (hierarchyRow != null)
                        {
                            IterateChildRows(hierarchyRow);
                        }
                    }
                }
                rowInfo.ActiveView = currentView;
            }

  • Dess
    Admin
    Dess avatar
    1601 posts

    Posted 20 Apr Link to this post

    Hello Fariba,

    Thank you for writing.

    Please refer to our Demo application >> GridView >> Filtering >> Custom Filtering example which is quite useful on this topic. It uses the custom filtering functionality that RadGridView offers to control the filtering logic.

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

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  • Back to Top
    UI for WinForms is Visual Studio 2017 Ready