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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Data Annotation - Fill Datagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

132106 Aug 14,2017 05:59 PM UTC Aug 16,2017 04:18 AM UTC Windows Forms 3
loading
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?
Ex:
[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 
{ 
                get 
                { 
                                return this.cat_Name; 
                } 
                set 
                { 
                                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 
 
Note:  
Moreover, you can use GridGroupingControl instead of GridDataboundGridGridGroupingControl has more features and more flexibility compared to GridDataBoundGrid. 
 
 
Regards, 
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.    
   
Regards,   
Arulpriya 


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

;