Skip to main content Skip to footer

How to Dynamically Add Columns to a FlexGrid at Runtime

How to Dynamically Add Columns to a FlexGrid at Runtime

The purpose of this article is to display the code necessary for dynamically adding columns to a FlexGrid at runtime. 

First, you'll want to create a simple button or similar event that can be triggered to execute the code.

Then, from within the event, you'll create a new GridColumn by writing

grid.Columns.Add(new GridColumn() { ColumnName = "Additional Column", Header = "Additional Column" });

Please note that you will want to be sure to use the GridColumn class and not the GridColumnItem class when creating this new column, as the GridColumnItem class binds the column to the underlying ItemSource, meaning the new column will contain the values from the previously created columns.

Tags:

Hunter Haaf