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

This constraint cannot be enabled as not all values have corresponding parent values.

4 Answers 2709 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jo
Top achievements
Rank 1
jo asked on 15 Sep 2009, 08:27 PM

This is my data on datasource-

COMPANYID CATEGORYID COMPANYNAME CATEGORYNAME
687d6bf7 103b9297 a123 abc
687d6bf7 6903d527 a123 xyz

This is my code-

<

 

telerik:RadTreeView ID="RadTreeView1" runat="server" DataSourceID="ObjectDataSourceCompany"

 

 

DataTextField="COMPANYNAME" DataFieldID="CATEGORYID" DataFieldParentID="COMPANYID"

 

 

DataValueField="CATEGORYID">

 

 

</telerik:RadTreeView>

This is the Error-

 

This constraint cannot be enabled as not all values have corresponding parent values.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: This constraint cannot be enabled as not all values have corresponding parent values.

Did I miss anything...How do i fix this??

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Sep 2009, 10:31 AM
Hello Jo,

The ParentID of the root items should be null. If for some reason the data source comes without null values for the ParentID column, the solution is to create a query that returns the expected value (null). Check out the code below which shows how to convert ParentID= 0 to ParentID=null
SELECT ID, Text, IF(ParentID = 0, NULL, ParentID) FROM table

You may also go throught he following links which refers to the above mentioned:
Treeview Problem

-Princy.
0
JohnRah
Top achievements
Rank 2
answered on 11 Mar 2015, 11:09 PM
Or you can use:

SELECT
    ID, Text,
    CASE WHEN ParentID=0
        THEN NULL
         ELSE ParentID
    FROM table
0
Sachita
Top achievements
Rank 1
answered on 12 Jan 2021, 05:59 AM

  private static void CreateDataRelations(ref DataSet ds, bool createConstraints)
        {

            DataRelation dataRelation = new DataRelation("PublicationTypeChildren",
                ds.Tables[0].Columns[(int)PublicationTypeColumns.Guid],
                ds.Tables[1].Columns[(int)PublicationTypeChildrenColumns.ParentGuid],
                createConstraints);
            ds.Relations.Add(dataRelation);
            
        }

As I have tried Solutions of Many Posts but didnot get any Luck,Can you please help.

0
Peter Milchev
Telerik team
answered on 14 Jan 2021, 02:45 PM

Hello Sachita,

As the error message says, the data has entries that have a non-existent parent node. To debug that, I would recommend to:

1) Get all ParentIDs of all entries

2) Check if each of the ParentIDs have a corresponding item with ID equal to the ParentID

Once you do that, you should find which entries have non-existent parents and fix them.

Regards,
Peter Milchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeView
Asked by
jo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
JohnRah
Top achievements
Rank 2
Sachita
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or