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
close icon

Creating column by code

Hello,

I need to create a grid with more than hundred of column by code.
I set ItemSource with an ObservableCollection.

when i try to create column i get error. Is it possible to have some small exemple for creating column by code ?

Thanks in advance,


Have a nice day.


3 Replies

SR Sivakumar R Syncfusion Team February 29, 2016 01:24 PM UTC

Hi Anthony,

You can achieve your requirement by adding column in XAML and code behind to columns property.
http://help.syncfusion.com/silverlight/sfdatagrid/columns

C#

this.dataGrid.Columns.Add(new GridTextColumn() {  MappingName = "Name" });

this.dataGrid.Columns.Add(new GridTextColumn() {  MappingName = "Year" });

this.dataGrid.Columns.Add(new GridTextColumn() { HeaderText = "Sales in Quarter1", MappingName = "QS1" });

this.dataGrid.Columns.Add(new GridTextColumn() { HeaderText = "Sales in Quarter2", MappingName = "QS2" });

this.dataGrid.Columns.Add(new GridNumericColumn() { HeaderText = "Sales in Quarter3", MappingName = "QS3" });
this.dataGrid.Columns.Add(new GridNumericColumn() { HeaderText = "Sales in Quarter4", MappingName = "QS4" });


Sample:
http://www.syncfusion.com/downloads/support/forum/123221/SILVER~1-2070827274.ZIP

Please let us know if you have any queries.

Regards
Gnanasownthari T.


AP Anthony PALLINI May 19, 2016 03:56 PM UTC

Hello,

Is it possible to have the same thing for GridDataControl ?

I need to bind a obverservable collection from a class with an array of values.

Thanks again.


SV Srinivasan Vasu Syncfusion Team May 20, 2016 04:42 PM UTC

Hi Anthony, 
 
We have analyzed your query and you can achieve your requirement in GridDataControl using VisibleColumns collection. 
 
Please refer the below code example. 
 
C# 
  this.grid.VisibleColumns.Add(new GridDataVisibleColumn() { MappingName = "Name", HeaderText = "name" }); 
 
 
We have recommended you to use only SfDataGrid in your application and currently we have implemented many features in SfDataGrid. SfDataGrid has been designed based on the template-based architecture which provides support to customize the datagrid easily. Comparatively, the performance of SfDataGrid control is better than the GridDataControl. 
 
Sample Location: SILVER-1-2070827274 
 
 
Regards,
Srinivasan 
 



Loader.
Live Chat Icon For mobile
Up arrow icon