Self referencial grid with GUID as ID.

Hi, I've got an issue that I'm trying to resolve for some days now : 

I'm trying to make a self referencial grid inside a gridgroupingcontrol using 2 GUID for the ID and the ParentID. ParentID is null for the top level rows.

I've got something that almost work using your TreeGridHelper just by modifying some lines : 



string filter = string.Format("[{0}] IS NULL", matchProperty);

string filter = string.Format("[{0}] = '{1}'", this.matchProperty, s);



As you can see in the screenshot, it works for expanding nodes. But it cannot revert the expanding as the "GetPrimaryID" function return an INT and an System.InvalidCastException pops up.

Any idea to resolve this problem ?

Thanks.


3 Replies

MG Mohanraj Gunasekaran Syncfusion Team July 27, 2018 01:03 PM UTC

Hi Yoann, 
 
Thanks for using Syncfuison product. 
 
The reported issue “System.InvalidCastException” may be occurred due to invalid casting of object by different type. So use the int.TryParse method to parse the integer variable. This will avoid the exception. Please refer to the below code example:   
  
Sample link: GridGroupingControl   
   
If you are getting the string type of data in GetPrimaryId method, then do cross check your sample for the reason why you are getting the string type of value in GetprimaryId method. let us know, if you are facing the different issue in your project and provide the details about the additional customization in grid and TreeGridHelper class. It will be more helpful to assist you.   
  
Please let us know if you have any concerns.   
 
Regards, 
Mohanraj G 
 



YG Yoann Gaborieau July 27, 2018 02:15 PM UTC

Thanks, I already looked into this and it doesn't really help me because I use GUID.

Anyway, I've tried another method and using a simple GridGroupingControl but I'm facing another issue :

I'm facing an issue with DataSet and gridgroupingcontrol.

I have a self relation on a table. Every row has childs, childs have childs etc ... I'm filling a DataTable with all of those line and use a DataSet relation like this :

DataRelation parentChildRelation = new DataRelation("ParentChild", ds.Tables[0].Columns["testNumericId"], ds.Tables[0].Columns["ParentIdNumeric"], false);

Problem is when I want to display this DataSet. It has the parent with all the child + one line for every child in my gridgroupingcontrol.

Parent 1
    Child 1
      Child 1-1
      Child 1-2
    Child 2
       Child 2-1
         Child 2-1-1
Child 1
Child 1-1
Child 1-2
etc ...






Any idea on what could be the issue ? How can I hide those Childs (they shouldn't appear) and only show rows with -1 as ParentIdNumeric ?

Thanks.



MG Mohanraj Gunasekaran Syncfusion Team July 30, 2018 12:17 PM UTC

Hi Yoann, 
  
Thanks for your update. 
  
Query 
Solution 
Problem is when I want to display this DataSet. It has the parent with all the child + one line for every child in my gridgroupingcontrol. 
  
By default, every child table generating the AddNewRow before that recor details. In order to avoid this  new row generating for every child, you can get the TableDescriptor for ChildTable using GetTableDescriptor method and disable the AllowNew preoperty. Please refer to the below code example,  
  
Code 
this.gridGroupingControl1.GetTableDescriptor("ChildTable”).AllowNew = false; 
How can I hide those Childs (they shouldn't appear) and only show rows with -1 as ParentIdNumeric ? 
  
To display the specific row in the GridGroupingControl, you could use the QueryRowHeight event to hide the rows using Size property. Please refer to the below code example, KB link and the sample, 
  
Code example 
this.gridGroupingControl1.TableModel.QueryRowHeight += TableModel_QueryRowHeight; 
  
private void TableModel_QueryRowHeight(object sender, GridRowColSizeEventArgs e) 
{ 
    Element el = this.gridGroupingControl1.Table.DisplayElements[e.Index]; 
    if (el != null) 
    { 
        Record r = el.GetRecord(); 
        if (r != null) 
        { 
            string value = r.GetValue("ParentNumericId").ToString(); 
            if (!value.Equals("-1")) 
            { 
                e.Size = 0; 
                e.Handled = true; 
            } 
        } 
    } 
} 
  
Sample link: GridGroupingControl 
  
  
  
  
Please let us know if we misunderstood your requirement. 
  
Regards, 
Mohanraj G 


Loader.
Up arrow icon