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

Data Annotation - Fill Datagrid

Thread ID:





132106 Aug 14,2017 05:59 PM UTC Aug 16,2017 04:18 AM UTC WinForms 3
Tags: GridDataBoundGrid(Classic)
Rodrigo Ferro Siqueira
Asked On August 14, 2017 05:59 PM UTC

Is there a way to use "Data Annotation - Properties" to populate the DataGridView without having to set column name?
[Column("First Name")]
public string FirstName { get; set; }
[Column("Last Name")]
public string LastName { get; set; }

Mohanraj Gunasekaran [Syncfusion]
Replied On August 15, 2017 07:45 AM UTC

Hi Rodrigo, 

Thanks for Syncfusion product. 

In GridDataBoundGrid can populate the columns automatically based on the bounded collection underlying datasource but does not have the direct support for Data Annotation. But, you can achieve your scenario by using HeaderText property. Please refer to the below code example 
Code example 
Using System.ComponentModel.DataAnnotations; 
[Display(Name = "Category Name")] 
public string CategoryName 
                                return this.cat_Name; 
                                this.cat_Name = value; 
Data d = new Data(); 
foreach (GridBoundColumn column in columns) 
    var col = (d.GetType().GetProperty(column.MappingName)).GetCustomAttributes(typeof(DisplayAttribute), true); 
    if (col is DisplayAttribute[] && (col as DisplayAttribute[]).Count() > 0) 
        string headerText = (col as DisplayAttribute[])[0].Name; 
        column.HeaderText = headerText; 
Sample link: GridDataBoundGrid 
Moreover, you can use GridGroupingControl instead of GridDataboundGridGridGroupingControl has more features and more flexibility compared to GridDataBoundGrid. 
Mohanraj G 

Rodrigo Ferro Siqueira
Replied On August 15, 2017 05:17 PM UTC

Thanks... it Works =)

Arulpriya Ramalingam [Syncfusion]
Replied On August 16, 2017 04:18 AM UTC

Hi Rodrigo,    
We are glad to hear that the provided solution was resolved your scenario.   
Please let us know if you need further assistance.    


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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