I want to show the contain object at the same level as main object. Is there are way to achieve this.
public class ClassA{ public string Field1 { get; set; } public string Field2 { get; set; } public ClassB { get; set; }} public class ClassB{ public string Field3 {get; set; }}
public class ClassA{ public string Field1 { get; set; } public string Field2 { get; set; } public ClassB { get; set; }}
public class ClassB{ public string Field3 {get; set; }}
I want Field1, Field2, Field3 to appear at the same level.
PS: I found the post with this subject in WPF forum, the example comes from that post :-)
You could create an unbound column in the grid on the parent band and use a couple of events to copy the data.
Or, if you want to get really fancy, you could implement ITypedList on your data source and return an extra PropertyDescriptor or two on the main list which knows how to get to the child data and returns it as a property.
I have done what you have suggested. However I was looking for some smart way of doing this without having to repeat the fields. I read about some other grid control implementing this using custom attributes.
If you can, add this property in classA:
public string Field3
{
get { return classB.Field3; }
set { classB.Field3 = value; }
}
If you can't, add an unbound column named Field3 and in InitializeRow event write this:
var item = e.Row.ListObject as ClassA;
e.Row.Cells["Field3"].Value = item.classB.Field3;