Salim,
you can also dynamically loop through the properties in your list and add them manually to the Fields collection.
For example try this:
FieldDescriptorCollection fields = _testGrid.TableDescriptor.Fields;
fields.Clear();
PropertyDescriptorCollection pdc = ListUtil.GetItemProperties(list);
for (int n = pdc.Count-1; n >= 0; n--)
{
PropertyDescriptor pd = pdc[n];
if (ListUtil.IsComplexType(pd))
{
// put here condition when to include nested properties.
AddNestedProperties(fields, pd.Name, pd.PropertyType, 0);
}
else
fields.Add(pd.Name);
}
_testGrid.DataSource = list;
void AddNestedProperties(FieldDescriptorCollection fields, string prefix, Type propertyType, int level)
{
PropertyDescriptorCollection pdc = ListUtil.GetItemProperties(propertyType);
if (pdc.Count > 0)
{
foreach (PropertyDescriptor pd in pdc)
{
// Add here criteria when to step into nested type.
if (ListUtil.IsComplexType(pd) && level < 2)
AddNestedProperties(fields, prefix + "." + pd.Name, pd.PropertyType, level+1);
else
fields.Add(prefix + "." + pd.Name);
}
}
}
I have attached a sample with this code.
Other options you have is to set the Browsable(false) attribute for certain properties. But that is then an all or nothing solution.
You could however have a derived class for "TestPatient" and only set Browsable(false) in that derived class for the property.
As I understand your problem, the key is that in your scenario you want to get the nested properties for the same type only if it is not more than 2 levels deep.
The sample I mentioned before is here:
TestSyncfusionIssue.zip
Stefan