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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

flattening entity data

Thread ID:

Created:

Updated:

Platform:

Replies:

53950 Dec 25,2006 01:04 PM UTC Jan 11,2007 07:34 AM UTC WinForms 9
loading
Tags: GridControl
Dinesh Upreti
Asked On December 25, 2006 01:04 PM UTC

hi,
consider the following entities.

public class Address
{
string street;
}

public class Customer
{
private int _name;
Dictionary _addresses;
public int Name
{
get { return _name; }
set { _name = value; }
}
}

As shown, Customer entity has a collection of Address entity. (a customer has more than one address).
The problem is that when i want to show the data in syncfusion grid, i want to have a flat display of data. e.g. for a customer having three adresss. i want the data to look like:

Customer Address1 Address2 Address3
Name Street Street Street
======= ======== ======== ========
Dinesh ABC DEF XYZ


After data has been displayed, i want to be able to sort, filter and subtotal the grid.
Please let me know whether thats possible, preferable with an example.

Thanks and regards

Dinesh Upreti

Administrator [Syncfusion]
Replied On December 26, 2006 04:40 AM UTC

Hi Dinesh,

When you bind a business object which itself contains some custom objects (like "Address" object ), the grouping grid will go down into the hierarchy and will create one column descriptor for each and every column in this hierarchy. Suppose if your "Address" class contains two members, the grouping grid will display these two columns and their record values where as the datagrid or databound grid will not show the record values

Here is a sample.
BindingArrayList_.zip

Best Regards,
Haneef

Dinesh Upreti
Replied On December 26, 2006 12:33 PM UTC

Thanks for the reply.
But my problem is somewhat different. Let me try to rephrase it. Lets say a collection has 5 items so when i bind it to grid, in a normal scenario, i would see five rows and a cloumn. I want to see 5 columns in a row. To further extend it to your example, if you have a dictionary object Address (having Address objects from your example, the number of which is not known at design time), how would that be handled. so for example, if a customer in your example has 5 address (which is decided at run time), how will that be handled




>Hi Dinesh,

When you bind a business object which itself contains some custom objects (like "Address" object ), the grouping grid will go down into the hierarchy and will create one column descriptor for each and every column in this hierarchy. Suppose if your "Address" class contains two members, the grouping grid will display these two columns and their record values where as the datagrid or databound grid will not show the record values

Here is a sample.
BindingArrayList_.zip

Best Regards,
Haneef

Dinesh Upreti
Replied On December 26, 2006 02:41 PM UTC

I modified the sample you have given as per my requirement.

In Data.cs, instead of address property, i create addresses property instead of address property as shown below (and accordingly modify the constructor).


private DataCollection addresses;

public DataCollection Addresses
{
get { return addresses; }
set { addresses = value; }
}


In form.cs,

i do the following change

Address add1 = new Address("5th Avenue", "Chennai");
Address add2 = new Address("6th Avenue", "Mumbai");
DataCollection addresses = new DataCollection();


dataSource.Add(new Data("1", "Condiments", "Sweets", "",addresses));

It doesnt binds the data by drilling down addresses collection as you suggeted.
Thanks


>Thanks for the reply.
But my problem is somewhat different. Let me try to rephrase it. Lets say a collection has 5 items so when i bind it to grid, in a normal scenario, i would see five rows and a cloumn. I want to see 5 columns in a row. To further extend it to your example, if you have a dictionary object Address (having Address objects from your example, the number of which is not known at design time), how would that be handled. so for example, if a customer in your example has 5 address (which is decided at run time), how will that be handled




>Hi Dinesh,

When you bind a business object which itself contains some custom objects (like "Address" object ), the grouping grid will go down into the hierarchy and will create one column descriptor for each and every column in this hierarchy. Suppose if your "Address" class contains two members, the grouping grid will display these two columns and their record values where as the datagrid or databound grid will not show the record values

Here is a sample.
BindingArrayList_.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On December 27, 2006 07:22 AM UTC

Hi Dinesh,

You can add UnBoundFieldDescriptor for the columns that you want to dynamically display from ChildList to the grid. Then use QueryValue event to dynamically provide the values from the child list. If you want to handle editing, you would also have to handle SaveValue event. Here is a code snippet to show this

PropertyDescriptorCollection childColumns = TypeDescriptor.GetProperties(add);
int ChildPropertyCount = childColumns.Count;
for(int i = 0;i this.gridGroupingControl1.TableDescriptor.UnboundFields.Add(string.Format("{0}",childColumns[i].Name));

//For display purpose....
private void gridGroupingControl1_QueryValue(object sender, FieldValueEventArgs e)
{
this.gridGroupingControl1.QueryValue -=new FieldValueEventHandler(gridGroupingControl1_QueryValue);
Record rec =e.Record.NestedTables[0].Records[0];
string sColumnName = rec.GetValue(e.Field.Name).ToString();
this.gridGroupingControl1.QueryValue +=new FieldValueEventHandler(gridGroupingControl1_QueryValue);
e.Value = sColumnName;
}

//Used for saving/Editing the data in the filed.
private void gridGroupingControl1_SaveValue(object sender, FieldValueEventArgs e)
{
this.gridGroupingControl1.SaveValue -=new FieldValueEventHandler(gridGroupingControl1_SaveValue);
Record rec =e.Record.NestedTables[0].Records[0];
rec.SetValue(e.Field.Name,e.Value);
this.gridGroupingControl1.SaveValue +=new FieldValueEventHandler(gridGroupingControl1_SaveValue);
}

Here is a sample.
BindingArrayList.zip

Best Regards,
Haneef

Dinesh Upreti
Replied On December 28, 2006 06:54 AM UTC

hi,
Thanks for the reply.
I tried running your sample but e.Record.NestedTables[0] is returning null

Record rec =e.Record.NestedTables[0].Records[0];

So it is throwing an exception at run time. if you can make that sample running completely, it would be great.

Regards

Dinesh upreti

Administrator [Syncfusion]
Replied On December 28, 2006 07:25 AM UTC

Hi Dinesh,

I have tested this issue by creating a sample in v.4.2 and then again tested by upgrading to 4.3/4.4. I was not able to reproduce the issue. May be I am not following the steps that you are doing. Attached sample working fine here.If you can provide more information, we can try to suggest some solution.

Here is a sample.
ModifiedBindingArrayList.zip

Could you please run this at your end and let me know how it goes?

Thanks for your patience.
Regards,
Haneef

Dinesh Upreti
Replied On December 29, 2006 06:58 AM UTC

Hi,
The problem remains.
Actually you have created the solution in VS2003. Till the last time, i reported error, i had converted the solution to use in VS2005 as that is the version we are using. So I thought some problem has occured because of conversion.
So this time I opened it using VS2003, keeping the solution as you had sent without conversion.As you wrote, this time it did not showed me the runtime error as it had shown me in VS2005. however, if you look carefully at the output, it doesn't shows up any Address data in grid. When i put a breakpoint at the following line in the code you have sent

Record rec =e.Record.NestedTables[0].Records[0];

in gridGroupingControl1_QueryValue function, and add a watch for rec, it shows me null. And if you access count property of NestedTables, its showing 0. Starngely, it doesn't throws up an exception in VS2003.


Thanks dinesh

dinesh upreti
Replied On January 11, 2007 06:21 AM UTC

Hi,
did you get a chance to look into my problem.


Thanjs

Administrator [Syncfusion]
Replied On January 11, 2007 07:34 AM UTC

Hi Dinesh,

Thanks for the update and for being patience. Is it possible for you to explain us more details or modify the sample, so it help us to solve your issue earlier. The following is the video clip demonstrates the e.Record.NestedTables[0].Records is working fine for the above sample, please let us know if you meant different scenario.

Here is a video clip.
BindingArrayList_video.zip

Best Regards,
Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;