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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Conditionally Hiding Child Groups in a GridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

45803 Jun 28,2006 09:09 PM UTC Jul 5,2006 03:48 PM UTC Windows Forms 14
loading
Tags: Grouping
Scott Mercer
Asked On June 28, 2006 09:09 PM UTC

Hi, I need to conditionally hide a child group based on a specific record value in the parent row. I''ll attempt to give an example that makes sense. Suppose we have a parent table that represents a widget. Let''s say that some widgets are battery powered and some are not. Widgets that are battery powered must show a battery service log. The battery service log table is a child of the widget table. I want to display all types widgets at the top level of the grid. Only battery powered widgets should be expandable to show the battery service log. Is this type of functionality possible, and if so what approach should I take? Thanks, Scott

Administrator [Syncfusion]
Replied On June 28, 2006 10:53 PM UTC

Hi Scott, Hide all the record in a group: To hide the records in a group, you need to handle the QueryCellStyleInfo event in a GridGroupingGrid. Here is a code snippet. //Hide all the record in a Show group having the cellvalue "1" if( e.TableCellIdentity.GroupedColumn != null && e.TableCellIdentity.GroupedColumn.Name == "Show" ) { if( e.TableCellIdentity.DisplayElement.ParentGroup.Category.ToString() == "1" ) { ((IGridRowHeight)e.TableCellIdentity.DisplayElement).RowHeight = 0 ; e.Handled = true; } } Here is a sample. http://www.syncfusion.com/Support/user/uploads/GGCAutoHeightAndResize_f400baab.zip Hide the record depends on the cell value: Could you try this code to resize the row height depends on the cell value in a grid. Here is a code snippet. private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { if(e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record) { object obj = e.TableCellIdentity.DisplayElement.ParentRecord.GetValue("Show"); if( obj != null && obj.ToString() != string.Empty ) { try { int show = int.Parse(obj.ToString()); if(show == 1) { ((IGridRowHeight)e.TableCellIdentity.DisplayElement).RowHeight = 0 ; e.Handled = true; } } catch { } } } } Here is a sample. http://www.syncfusion.com/Support/user/uploads/GGCAutoHeightAndResize_deafb336.zip Let me know if this helps. Best Regards, Haneef

Scott Mercer
Replied On June 29, 2006 04:20 PM UTC

Hi Haneef, Thanks for taking the time to look into my issue. I looked at your examples and it looks like creating a custom engine is the key. I was able to hide the rows by setting their height to 0. What I really want to do is supress the entire child table grouping for a specific parent. I tried to override the "CreateRecordsDetails" and "CreateNestedTable" factory methods, but they don''t seem to support the IGridRowHeight interface. Which factory "Create" methods do I need to override and which interfaces do I need to implement to make this work properly? Thanks, Scott >Hi Scott, > >Hide all the record in a group: > >To hide the records in a group, you need to handle the QueryCellStyleInfo event in a GridGroupingGrid. Here is a code snippet. > >//Hide all the record in a Show group having the cellvalue "1" >if( e.TableCellIdentity.GroupedColumn != null && e.TableCellIdentity.GroupedColumn.Name == "Show" ) >{ > if( e.TableCellIdentity.DisplayElement.ParentGroup.Category.ToString() == "1" ) > { > ((IGridRowHeight)e.TableCellIdentity.DisplayElement).RowHeight = 0 ; > e.Handled = true; > } >} > >Here is a sample. >http://www.syncfusion.com/Support/user/uploads/GGCAutoHeightAndResize_f400baab.zip > >Hide the record depends on the cell value: > >Could you try this code to resize the row height depends on the cell value in a grid. Here is a code snippet. > >private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) >{ > if(e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record) > { > object obj = e.TableCellIdentity.DisplayElement.ParentRecord.GetValue("Show"); > if( obj != null && obj.ToString() != string.Empty ) > { > try > { > int show = int.Parse(obj.ToString()); > if(show == 1) > { > ((IGridRowHeight)e.TableCellIdentity.DisplayElement).RowHeight = 0 ; > e.Handled = true; > } > } > catch > { > } > } > } >} > >Here is a sample. >http://www.syncfusion.com/Support/user/uploads/GGCAutoHeightAndResize_deafb336.zip > >Let me know if this helps. >Best Regards, >Haneef

Administrator [Syncfusion]
Replied On June 29, 2006 07:11 PM UTC

Hi Scott, I have created a sample as per your specification. The sample implements the custom engine with CreateRecordsDetails overriden method. It also implements IGridRowHeight. Please refer to the attached sample and let us know if you are trying something different. Here is a sample. http://www.syncfusion.com/Support/user/uploads/GGC_NestedTabelHide_eb4f9e73.zip Let me know if this helps. Best Regards, Haneef

Scott Mercer
Replied On June 29, 2006 09:28 PM UTC

Hey Haneef, I suppose I''m not explaining what I want to do accurately. I composed an example project that explains what I wish to accomplish. Look in the "LoadData()" method of MainForm.cs for more information. Looking at my sample code, I want to hide the WidgetMaintenanceLog for the "Tonka Truck" widget entry. Not only do I want to hide the rows, but I also want to hide the entire table grouping itself. The user should not be able to see that a WidgetMaintenanceLog table exists for the "Tonka Truck" entry. If the user were to change the WidgetTypeID value for the "Tonka Truck" to "Industial Widget" then the entire WidgetMaintenanceLog child table would become available. I hope that this explanation makes more sense than the previous ones. :-) Thanks, Scott

NestedTableHide.zip

Administrator [Syncfusion]
Replied On June 29, 2006 10:23 PM UTC

Hi Scott, Please refer to the attached sample and let me know if you are trying something different. http://www.syncfusion.com/Support/user/uploads/NestedTableHide_340ba711.zip Best Regards, Haneef

Scott Mercer
Replied On June 30, 2006 01:44 PM UTC

Haneef, Your sample code is supressing the "Tonka Truck" row, which is not what I want to do. I want to supress the entire child table of "Tonka Truck", which is the WidgetServiceLog. I want to make it look like the "Tonka Truck" has no WidgetServiceLog entries. The entire WidgetServiceLog child table grouping should be hidden for this object only. Do you think this is possible? Thanks, Scott

Administrator [Syncfusion]
Replied On June 30, 2006 06:43 PM UTC

Hi Scott, Try this code in RecordExpanding event. if( e.Record != null ) { object obj = e.Record.GetValue("WidgetTypeID"); if( obj != null && obj.ToString() == "2") e.Cancel = true; } Here is a sample. http://www.syncfusion.com/Support/user/uploads/NestedTableHide_efe6c544.zip Let me know if this helps. Best Regards, Haneef

Scott Mercer
Replied On June 30, 2006 08:01 PM UTC

Haneef, The example you gave me does not have child relations in the DataSet and is still hiding rows only. I want to selectively hide entire child tables depending on data in the parent row. You are setting a grouping on one table. This has the effect of creating child objects, but it doesn''t behave the same way as a DataSet primary-foriegn key relation. Look again at my Widget Service Log example. I want to disable the entire Widget Service Log for a "Toy Widget". I have already moved on and found an alternate solution to the problem. I broke each Widget type into a different table. Each Widget type table has a different set of child tables, accomplishing the affect I want. However, synchronization of data is now very messy. Let me know if you come up with a solution to my original problem because this is something that I have to deal with quite often. Thanks, Scott

Administrator [Syncfusion]
Replied On June 30, 2006 10:11 PM UTC

Hi Scott, I have modified your sample in my previous post. In that sample, I have canceled the record expanding event at particular parent record having the WidgetTypeID is (2) "Toy Widget" instead of hidding the child table. I am not hidding the any records. I have once again attached sample here. Please refer this sample for more details. Kindly provide us more details, if your requirement is different. Sample : ConditionallyCanceltheRecordExpand.zip Best Regards, Haneef

Scott Mercer
Replied On July 3, 2006 03:58 PM UTC

Haneef, My apologies. Your example did indeed disable the expand event for the "Toy Widget". I must have opened the previous example project by mistake. However, disabling the expand event does not accomplish the effect I am looking for. This approach has 2 problems. 1) The expand button is still clickable. This is a little misleading from an end user perspective. They might think that something is wrong with the application. If we could somehow disable the expand button for the "Toy Widget" that would be better. 2) The "Toy Widget" might have other child tables that we want to display. Disabling the expand event would prevent us from displaying any other child tables. Hiding a specific child grouping is the only way that I can think of to solve the 2 problems that I have stated above. I have modified the example that you posted in the previous message by adding an additional table, "WidgetPartsList". I want to display the WidgetPartsList grouping for all Widgets while hiding the "WidgetMaintenanceLog" for all widgets that have a WidgetType of "Toy Widget". I appreciate your persistance it trying to solve my problem. Thanks, Scott

ConditionallyCanceltheRecordExpand.zip

Administrator [Syncfusion]
Replied On July 3, 2006 05:53 PM UTC

Hi Scott, Thanks for your update. I have created a sample as per your specification. The sample implements the custom engine with CreateRecordsDetails overriden method and also implements IGridRowHeight interface to hide the particular table. It hides the WidgetMaintenanceLog table for the parentRecord having the widgetTypeId is "Toy Widget". Please refer to the attached sample and let us know if you are trying something different. private void SetRowHeight(NestedTablesCollection tables,int Height) { foreach( NestedTable table in tables ) { if( table.ChildTable != null && table.ChildTable.Name == "WidgetMaintenanceLog" ) { foreach( Element el in table.ChildTable.DisplayElements) { ((IGridRowHeight)el).RowHeight = Height ; } } } } Here is a sample. http://www.syncfusion.com/Support/user/uploads/SetHeightOnTable_f73670e3.zip Best Regards, Haneef

Scott Mercer
Replied On July 3, 2006 07:26 PM UTC

Haneef, I think we are on the right track now, but this solution is a little buggy. To reproduce, open and run the last solution you posted for me (SetHeightOnTable_f73670e3.zip). 1) Expand the "Bulldozer" node. This displays correctly with both WidgetMaintenanceLog and WidgetPartsList child tables. 2) Expand the "Tonka Truck" node. The WidgetMaintenanceLog is hidden appropriately for the "Tonka Truck". However, notice that the WidgetMaintenanceLog also dissapears for the "Bulldozer" node. If you collapse and reexpand the "Bulldozer" node it then redraws correctly. I spent about an hour trying to figure out why this is happening. It looks like we are looping through both child table subsets when the following foreach loop is executed: foreach (Element el in table.ChildTable.DisplayElements) { ((IGridRowHeight)el).RowHeight = Height ; } Just to validate my theory, I added a row to the WidgetMaintenanceLog for the "Bulldozer" entry. I could trace this row being disabled inside of this loop. If my initial findings are correct, how do we filter the ChildTable.DisplayElements to only the DisplayElements of the parent row? Thanks again, Scott

Administrator [Syncfusion]
Replied On July 3, 2006 09:10 PM UTC

Hi Scott, Try this code to resolve this issue. Here is a code snippet //Call the SetRowHeight method in RecordExpand event. SetRowHeight(e.Record, e.Record.NestedTables, 0) ; private void SetRowHeight(Record r , NestedTablesCollection tables,int Height) { foreach( NestedTable table in tables ) { if( table.ChildTable != null && table.ChildTable.Name == "WidgetMaintenanceLog" ) { foreach( Element el in table.ChildTable.DisplayElements) { if( el.ParentChildTable.ParentNestedTable.ParentRecord != null) { object obj = el.ParentChildTable.ParentNestedTable.ParentRecord.GetValue("WidgetTypeID"); if( obj != null && obj.ToString() == "2") { ((IGridRowHeight)el).RowHeight = Height ; } } } } } } Here is a sample. http://www.syncfusion.com/Support/user/uploads/SetHeightOnTableVersion3_73f931e1.zip Let me know if this helps. Best Regards, Haneef

Scott Mercer
Replied On July 5, 2006 03:48 PM UTC

Hi Haneef, Well, I think we have finally arrived. It finally does EXACTLY what I want! I had to make some small modifications, but overall the idea is the same. I posted my changed solution file just in case you are interested. Thanks for all your hard work! --Scott

SetHeightOnTableVersion4_Scott.zip

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

;