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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Creating column by code

Thread ID:

Created:

Updated:

Platform:

Replies:

123221 Feb 26,2016 03:41 PM UTC May 20,2016 04:42 PM UTC Silverlight 3
loading
Tags: GridDataControl
Anthony PALLINI
Asked On February 26, 2016 03:41 PM UTC

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.


Sivakumar R [Syncfusion]
Replied On 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.

Anthony PALLINI
Replied On 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.

Srinivasan Vasu [Syncfusion]
Replied On 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 
 



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

;