Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:51:03+00:00 2026-06-15T01:51:03+00:00

I have a simple data structure class: public class Client { public String name

  • 0

I have a simple data structure class:

public class Client {
    public String name {set; get;}
    public String claim_number {set; get;}
}

Which I am feeding into a DataGrid:

this.data_grid_clients.ItemSource = this.clients;

I would like to change the column headings. Ie: claim_number to “Claim Number”. I know this can be done when you manually create the columns by doing something like:

this.data_grid_clients.Columns[0].Header = "Claim Number"

However, the Columns property is empty when auto-generating the columns. Is there a way to rename the columns, or do I have to manually generate the columns?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:51:04+00:00Added an answer on June 15, 2026 at 1:51 am

    You can use DisplayNameAttribute and update some part of your code to achieve what you want.

    The first thing you have to do is, adding a [DisplayName("")] to properties in the Client class.

    public class Client {
        [DisplayName("Column Name 1")]
        public String name {set; get;}
    
        [DisplayName("Clain Number")]
        public String claim_number {set; get;}
    }
    

    The update you xaml code, add an event handler to AutoGenerationColumn event.

    <dg:DataGrid AutoGenerateColumns="True" AutoGeneratingColumn="OnAutoGeneratingColumn">
    </dg:DataGrid>
    

    Finally, add a method to the code-behind.

    private void OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        var displayName = GetPropertyDisplayName(e.PropertyDescriptor);
    
        if (!string.IsNullOrEmpty(displayName))
        {
            e.Column.Header = displayName;
        }
    
    }
    
    public static string GetPropertyDisplayName(object descriptor)
    {
        var pd = descriptor as PropertyDescriptor;
    
        if (pd != null)
        {
            // Check for DisplayName attribute and set the column header accordingly
            var displayName = pd.Attributes[typeof(DisplayNameAttribute)] as DisplayNameAttribute;
    
            if (displayName != null && displayName != DisplayNameAttribute.Default)
            {
                return displayName.DisplayName;
            }
    
        }
        else
        {
            var pi = descriptor as PropertyInfo;
    
            if (pi != null)
            {
                // Check for DisplayName attribute and set the column header accordingly
                Object[] attributes = pi.GetCustomAttributes(typeof(DisplayNameAttribute), true);
                for (int i = 0; i < attributes.Length; ++i)
                {
                    var displayName = attributes[i] as DisplayNameAttribute;
                    if (displayName != null && displayName != DisplayNameAttribute.Default)
                    {
                        return displayName.DisplayName;
                    }
                }
            }
        }
    
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a simple class with some storage data structure (list, vector, queue,
I have simple SSIS package which reads data from flat file and insert into
Let's say I have this simple structure class FooDefinition { public FooDefinition Parent {
I have a recursive data structure. Something like... Public Class Comparison Property Id As
I have a simple data structure (the properties are of course Dependency Properties): class
I commonly run into the following situation where I have a data structure which
Given the following classes: public class Lookup { public string Code { get; set;
I have huge amont of geographic data represented in simple object structure consisting only
I have simple SSIS package where I import data from flat file into SQL
I have a simple jasper report which shows some data from database. The jasper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.