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

Dynamically added column to underlying datasource not reflected in ggc

I have a ggc that is bounded to -> dsOrder.Tables["Lines"].

On another tab, I am dynamically adding a column to the datasource and add that columns to the grid visible columns collection to show it. But this is not working. My code snippet is below.

When debugging, I see that the columns is added to the datasource and that the visiblecolumn count goes up by 1, but the grid is not reflecting the change. I have tried gridGroupingControl1.Refresh(); and gridGroupingControl1.Update();


DataColumn col = new DataColumn("col1", typeof(int));
col.DefaultValue = 0;
dsOrder.Tables["Lines"].Columns.Add(col);
dsOrder.Tables["Lines"].AcceptChanges();
this.gridGroupingControl1.TableDescriptor.VisibleColumns.Add("col1");
bool b = this.gridGroupingControl1.TableDescriptor.VisibleColumns.Contains("col1");
gridGroupingControl1.Refresh();

7 Replies

AD Administrator Syncfusion Team December 11, 2006 04:23 AM UTC

Hi James,

After modifying the new data source try calling gridGroupingControl1.TableDescriptor.ResetColumns() to see if that helps.

DataColumn col = new DataColumn("col1", typeof(int));
col.DefaultValue = 0;
dsOrder.Tables["Lines"].Columns.Add(col);
dsOrder.Tables["Lines"].AcceptChanges();
this.gridGroupingControl1.TableDescriptor.ResetColumns();
//Or
this.gridGroupingControl1.TableDescriptor.Columns.Reset();
gridGroupingControl1.Refresh();

Best Regards,
Haneef


JB James Blibo December 11, 2006 04:41 PM UTC

SOrry.. this did not work


AD Administrator Syncfusion Team December 12, 2006 06:56 AM UTC

Hi James,

You can call TableDescriptor.ResetVisibleColumns() method to repopulate VisibleColumn collection from the Tabledescriptor.Columns collection.Please refer to the attached sample for implementation.

Sample : NestedTable_c8c76b11.zip

Best Regards,
Haneef


JB James Blibo December 12, 2006 02:14 PM UTC

It's still not working for me. I have using a CustomEngine with the grid to display the summary rows at the top. I'm not sure if this causing it. I added the custom engine to the project that you sent and i'm getting an error when I run the project.

I've attached the custom engine!

Also, I reported another problem about the CaptionSectionCell getting automatically selected when you click the plus/minus button. I wanted to prevent this behavior. When I added the custom engine to the project that you sent, it was happening. You can add the custom engine and see for yourself. Thanks for the help.

CustomEngine4.zip


AD Administrator Syncfusion Team December 13, 2006 12:46 PM UTC

Hi James,

Please refer to the following sample which demonstrates the adding of columns at run time, it uses the custom engine to have the summary row at the top. Is it possible for you to upload us more details or a demo sample or your property settings? So we would suggest you a better solution at the earliest.

Sample: GGC_AddingColumns.zip

Thank you for being patience.
Have a nice day.

Best regards,
Madhan


JB James Blibo December 13, 2006 02:58 PM UTC

Attached is a snippet of my ggc settings. Basically, just follow the ctor and you'll be able to trace the order.

basically, I have series of columns in the datasource.

I add a couple of expression columns after I get the dataTable.

Then I bind datatable to the grid.

After that I do a...

this.gridGroupingControl1.TableDescriptor.VisibleColumns.Clear();

so I can leave out selected columns that I do not want to display and also change the display order of the columns.

Then I add the summary columns, ect, and lastly I applied some grid settings.



gridsettings.zip


AD Administrator Syncfusion Team December 14, 2006 09:45 AM UTC

Hi James,

Thanks for your code snippet and for being patience.

By Default, the grouping grid will automatically respond to adding/removing columns in the datasource. In case, changing the this.gridGroupingControl1.TableDescriptor.VisibleColumns, the grid will automatically assumes that the user wants to control the columns that are being displayed and no longer will re-act to the adding/removing of columns in the datatable. Therefore, you need to explicitly add/remove the columns from the this.gridGroupingControl1.TableDescriptor.VisibleColumns collection as you add/remove columns from the datatable.

If you want the grid to automatically respond to adding/removing columns in the datatable, please not change the VisibleColumns collection in your code.

Kindly let us know if you need any further information.
Have a nice day.

Best regards,
Madhan

Loader.
Live Chat Icon For mobile
Up arrow icon