DataTable parentTable = GetParentTable();
DataTable childTable = GetChildTable();
DataTable grandChildTable = GetGrandChildTable();
GridRelationDescriptor parentToChildRelationDescriptor = new GridRelationDescriptor();
//Same as SourceListSetEntry.Name for Child Table.
parentToChildRelationDescriptor.ChildTableName = "MyChildTable";
parentToChildRelationDescriptor.RelationKind = RelationKind.RelatedMasterDetails;
parentToChildRelationDescriptor.RelationKeys.Add("parentID", "ParentID");
//Adds relation to Parent Table.
gridGroupingControl1.TableDescriptor.Relations.Add(parentToChildRelationDescriptor);
GridRelationDescriptor childToGrandChildRelationDescriptor = new GridRelationDescriptor();
//Same as SourceListSetEntry.Name for Grand Child Table.
childToGrandChildRelationDescriptor.ChildTableName = "MyGrandChildTable";
childToGrandChildRelationDescriptor.RelationKind = RelationKind.RelatedMasterDetails;
childToGrandChildRelationDescriptor.RelationKeys.Add("childID", "ChildID");
//Adds relation to Child Table.
parentToChildRelationDescriptor.ChildTableDescriptor.Relations.Add(childToGrandChildRelationDescriptor);
this.gridGroupingControl1.Engine.SourceListSet.Add("MyParentTable", parentTable);
this.gridGroupingControl1.Engine.SourceListSet.Add("MyChildTable", childTable);
this.gridGroupingControl1.Engine.SourceListSet.Add("MyGrandChildTable", grandChildTable);
this.gridGroupingControl1.DataSource = parentTable;
public Form1()
{
InitializeComponent();
// DataSource code//
this.GridSettings();
}
#region Grid Settings
public void GridSettings()
{
gridGroupingControl1.AllowProportionalColumnSizing = true;
//Setting the filter condition.
FilterCondition condition = new FilterCondition(FilterCompareOperator.GreaterThan, 50);
//Setting the RecordFilterDescriptor
RecordFilterDescriptor recordFilterDescriptor = new RecordFilterDescriptor("CategoryID", condition);
//Adding the RecordFilterDescriptor to collection
this.gridGroupingControl1.TableDescriptor.RecordFilters.Add(recordFilterDescriptor);
//To add the hidden columns
foreach (GridColumnDescriptor col in this.gridGroupingControl1.TableDescriptor.Columns)
{
if (!this.gridGroupingControl1.TableDescriptor.VisibleColumns.Contains(new GridVisibleColumnDescriptor(col.Name)))
{
this.gridGroupingControl1.TableDescriptor.VisibleColumns.Add(col.Name);
}
}
}
#endregion
//Button click Event Customization
private void reloadBtn_Click(object sender, EventArgs e)
{
this.gridGroupingControl1.DataSource = null;
this.gridGroupingControl1.DataSource = parentTable;
this.GridSettings();
} |