We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Child Rows not Displaying in a Hierarchical Grid

Hi, I''m using GridDataBoundGrid bound to a custom collection that sits on-top of the ADO.Net DataTable. I''m trying to implement a hierarchical display so have added a property "Children" (type IList) to each row and filled it with an ArrayList containing the same type of row objects that are in my custom collection. I then told the GDBG that the "Children" property should be used to obtain child rows. I''ve attached a small sample containing my code. It is bound to an MS DataGrid and a SyncFusion GridDataBoundGrid. It works with the MS DataGrid but the child rows appear blank with the Syncfusion grid. The grid set-up is performed in the Form1() constructor. Please could you tell me where I''m going wrong. I realize that this sample has a couple of shortcomings, notably ArrayList doesn''t implement notification so the grid will not update when the data changes. There is also a bug with editing. I''ll fix these once the basics are working. The reason for using a custom collection between DataTable and the grid is to give me greater control over sorting and in the production code it will dynamically filter the table and reassign some rows as children. Thanks, Ben Lamb.

4 Replies

AD Administrator Syncfusion Team November 3, 2004 11:59 AM UTC

I think you forgot to upload your sample.


AD Administrator Syncfusion Team November 3, 2004 12:16 PM UTC

Sorry, fixed. childgrid_3455.zip


AD Administrator Syncfusion Team November 3, 2004 01:47 PM UTC

I looked at your sample for a while. Here are a couple of things I saw. If you comment out these two lines, table.Rows.Add(row3); table.Rows.Add(row4); both the GridDataBoundGrid and DataGrid behave the same way (showing empty cells). Thus, I think the only reason the DataGrid can find the values with the code not commented is that the rows are a member of its table datasource. Are you trying to do self-references to the same table? If so, I am not sure you will be able to get this to work. The GridDataBoundGrid will try to display the public properties of the onject in the arraylist. Those properties are CUstomersDataRowView.Row and CustomersDataRowView.Pos. These are the 2 things the grid is trying to display when you see the 2 empty cells. You can actually get the grid to display them by having your ArrayList implement ITypedList.
public class MyArrayList : ArrayList, ITypedList
{
	public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
	{
		return TypeDescriptor.GetProperties(typeof(CustomDataRowView));
	}
	public string GetListName(PropertyDescriptor[] listAccessors)
	{
		return "CustomDataRowView";
	}
}
This will show you the values in the GridDataBoundGrid. So, one try at getting this to work is to create a custom property descriptor that retrieves the FirstName and Last given the Row object, and then use this custom descriptor in your ITyleList implementation.


AD Administrator Syncfusion Team November 4, 2004 11:30 AM UTC

Clay, Thanks for having a look at my sample. I understand what you''re saying, however, when I implemented MyArrayList as you suggest the GetItemProperties and GetListName are never called. "Are you trying to do self-references to the same table? If so, I am not sure you will be able to get this to work." No, self-references aren''t something I need to do. After much playing around I still couldn''t get it to work. So I went back to the basics and implemented a simple object and a collection. Even this didn''t work, the child rows were blank. I copied bits from SyncFusion''s Customer sample into my sample and hacked bits out of the SyncFusion sample to see what stopped it from working. Eventually I found the culprit: /// Default ctor needed for Xml and CodeDom serialization of strong-typed collections and /// for Essential Grid to be able to detect properties of items in strong-typed collections. /// public Customer() { I added a default constructor to my simple object and it worked perfectly. Unfortunately my real code, and sample I sent you, use DataRows which don''t have default constructors. I don''t see any way around this other than to replace ADO.Net with custom objects and a custom collection. It''s annoying that the grid can''t use the ITypedList to obtain the property information. The effect I am trying to achieve is to allow users to place rows into arbitrary groups, not all rows will be in a group. I could probably do it with ADO.NET by having two tables and moving rows between the tables. However, I think it will be easier to use custom collections. Thanks, Ben.

Loader.
Live Chat Icon For mobile
Up arrow icon