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

Clearing Nested table in gridGroupingControl

Hi, I want to clear nested table structure.Before clearing I need to check whether the grid has child table.How can I do it..? Thanks, Prathima

5 Replies

AD Administrator Syncfusion Team August 18, 2005 08:25 AM UTC

You can check this value to see if the grid has an hierarchical data source. bool hasChild = this.gridGroupingControl1.TableDescriptor.Relations != null && this.gridGroupingControl1.TableDescriptor.Relations.Count > 0;


PV Prathima Venkobachar August 18, 2005 09:07 AM UTC

I have a requirenment depending on the user choice(Check checkbox) I should show the nested table information. I am using the above condition and clearing the nested table column descriptor before binding it to the grid. First time it works fine i.e when checkbox is not checked. Next time if I check the checkbox.It works fine.It shows nested table information. I repeat the same, i.e uncheck and check again I am getting error.At this point.Columns are cleared. Also 2nd time when I uncheck, When there are no child reocrds it still displays ''+'' sign. How can I solve this..? //Code if (this.gridGroupingControl.TableDescriptor.Relations != null && this.gridGroupingControl.TableDescriptor.Relations.Count > 0) { GridEngine engine = this.gridGroupingControl.Engine; GridTableDescriptor viewTableDescriptor = (GridTableDescriptor) engine.TableDescriptor; RelationDescriptor ViewHistRelationDescriptor = ViewTableDescriptor.Relations["View_History"]; GridTableDescriptor ViewHistTableDescriptor = (GridTableDescriptor) ViewHistRelationDescriptor.ChildTableDescriptor; ViewHistTableDescriptor.Columns.Clear(); } Thanks, Prathima


AD Administrator Syncfusion Team August 18, 2005 12:40 PM UTC

If you do not want to see the nested tables, then one way to do this would be the call this.gridGroupingControl.TableDescriptor.Relations.Clear. Then when you want to see them again, add the relations back. Here is a button handler that either shows or hides nested tables each time you click it.
private void button1_Click(object sender, System.EventArgs e)
{
	if(saveRelations == null)
	{
		saveRelations = new ArrayList();
		foreach(GridRelationDescriptor rd in this.gridGroupingControl1.TableDescriptor.Relations)
			saveRelations.Add(rd);
		this.gridGroupingControl1.TableDescriptor.Relations.Clear();
	}
	else
	{
		foreach(GridRelationDescriptor rd in saveRelations)
			this.gridGroupingControl1.TableDescriptor.Relations.Add(rd);
		saveRelations.Clear();
		saveRelations = null;
	}
}


PV Prathima Venkobachar August 22, 2005 05:49 AM UTC

Hi, I tried to save the relation.This is not helping. My scenario is like this. I have to show history details in the nested tables.History data is huge.I don''t want to load always and keep in the dataset. Only when the user selects to view history..I load data to dataset .Otherwise I will have only datatable. Code looks like this.. //Clear Auto populated Coulmns before binding GridTableDescriptor tableDescriptor = this.gridGroupingControl.TableDescriptor; tableDescriptor.Columns.Clear(); tableDescriptor.VisibleColumns.Clear(); tableDescriptor.GroupedColumns.Clear(); foreach(GridSummaryRowDescriptor rd in sfgAssetView.TableDescriptor.SummaryRows) rd.SummaryColumns.Clear(); tableDescriptor.SummaryRows.Clear(); tableDescriptor.SortedColumns.Clear(); tableDescriptor.ExpressionFields.Clear(); tableDescriptor.ResetSummaries(); if (this.gridGroupingControl.TableDescriptor.Relations != null && this.gridGroupingControl.TableDescriptor.Relations.Count > 0) { GridEngine engine = this.gridGroupingControl.Engine; GridTableDescriptor viewTableDescriptor = (GridTableDescriptor) engine.TableDescriptor; RelationDescriptor ViewHistRelationDescriptor = ViewTableDescriptor.Relations["View_History"]; GridTableDescriptor ViewHistTableDescriptor = (GridTableDescriptor) ViewHistRelationDescriptor.ChildTableDescriptor; ViewHistTableDescriptor.Columns.Clear(); } //Bind datatable/dataset to the grid dataSet = new DataSet("ViewHistDet"); if (ShowHistory) { if (this.SrcDataSet != null) { DataTable dtHistoryDetails = GetTable("HISTORY_DETAILS"); dtHistoryDetails.TableName = "AWB_HISTORY_DETAILS_NESTED"; DataTable dtHist = dtHistoryDetails.Copy(); DataTable dt = this.dataTable.Copy(); dt.TableName = "AssetView"; if (!dataSet.Tables.Contains(dt.TableName)) { dataSet.Tables.Add(dt); } if (!dataSet.Tables.Contains(dtHist.TableName)) { dataSet.Tables.Add(dtHist); } } dataSet.Relations.Add(dataSet.Tables[0].Columns["Id"], dataSet.Tables[1].Columns["Id"]); dataSet.Relations[0].RelationName = "View_History"; this.gridGroupingControl.DataSource = dataSet.Tables[0]; }else { this.gridGroupingControl.DataSource = this.dataTable; } //Set Styles to Nested table if (showHistory) { GridEngine engine = this.gridGroupingControl.Engine; engine.ChildGroupOptions.ShowCaption = true; engine.NestedTableGroupOptions.ShowColumnHeaders = false; engine.NestedTableGroupOptions.ShowGroupHeader = false; engine.NestedTableGroupOptions.ShowCaption = false; engine.NestedTableGroupOptions.ShowCaptionPlusMinus = false; engine.NestedTableGroupOptions.ShowEmptyGroups = false; GridTableDescriptor ViewTableDescriptor = (GridTableDescriptor) engine.TableDescriptor; RelationDescriptor ViewHistRelationDescriptor = ViewTableDescriptor.Relations["View_History"]; GridTableDescriptor ViewHistTableDescriptor = (GridTableDescriptor) ViewHistRelationDescriptor.ChildTableDescriptor; ViewTableDescriptor.Appearance.AnyHeaderCell.Borders.All = new GridBorder(GridBorderStyle.None); ViewHistTableDescriptor.AllowNew = false; ViewHistTableDescriptor.AllowEdit = false; ViewHistTableDescriptor.Appearance.AnyNestedTableCell.Borders.All = new GridBorder(GridBorderStyle.None); ViewHistTableDescriptor.Appearance.AnyRecordFieldCell = ViewHistStyle; ViewHistTableDescriptor.Columns[0].Width = 75; // - Here I get a error - "Object reference not set to an instance" - ViewHistTableDescriptor.Columns[1].Width = 40; // Sometimes cast not valid or out of range.At this point the tabledescriptor ViewHistTableDescriptor.Columns[2].Width = 55; // is cleared. ViewHistTableDescriptor.Columns[3].Width = 55; ViewHistTableDescriptor.Columns[4].Width = 55; ViewHistTableDescriptor.Columns[5].Width = 55; ViewHistTableDescriptor.Columns[6].Width = 55; ViewHistTableDescriptor.Columns[0].Appearance.AnyRecordFieldCell = ViewHistDateStyle; ViewHistTableDescriptor.Columns[2].Appearance.AnyRecordFieldCell = ThreeDecimalStyle; ViewHistTableDescriptor.Columns[3].Appearance.AnyRecordFieldCell = ThreeDecimalStyle; } this.gridGroupingControl.TableDescriptor.Columns.LoadDefault(); // Apply styles to Parent table.. Everytime before binding I set relation to the dataset.. I tried saving and setting relation to the gridGroupingControl.tablesdescriptor...but this not working.. Thanks, Prathima


AD Administrator Syncfusion Team August 22, 2005 10:17 AM UTC

Can you upload a sample project showing what you are tring to do so we can run it here?

Loader.
Up arrow icon