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 4606062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:30:54+00:00 2026-05-22T00:30:54+00:00

I have a datagrid that I’m building the contents of programmatically as the columns

  • 0

I have a datagrid that I’m building the contents of programmatically as the columns will change based on the complex collection property of the object.
The object in question has say 2 standard properties.

public class MyObject
{
   private List<MyNameValuePairProps> props = new List<MyNameValuePairProps>();

   public int Id { get; set; }
   public string Name { get; set; }
   public List<MyNameValuePairProps> Props
   {
      get { return props; }
      set { props = value; }
   }
}

And programmatically I’m adding DataGridTextColumns per property like so:

DataGridTextColumn colId = new DataGridTextColumn();
colId.Header = "Id";
colId.Binding = new Binding("Id");
myDataGrid.Columns.Add(colId);

DataGridTextColumn colName = new DataGridTextColumn();
colName.Header = "Name";
colName.Binding = new Binding("Name");
myDataGrid.Columns.Add(colName);

How would I go about programmatically adding a column per “MyNameValuePairProp” in the “Props” list property of my object AND databind to that when I call this after I set up the columns:

myDataGrid.ItemsSource = myCollOfMyObjects;
  • 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-05-22T00:30:54+00:00Added an answer on May 22, 2026 at 12:30 am

    You can simply set the source on the binding (as below)

    foreach(MyNameValuePairProps pair in Props)
    {
        DataGridTextColumn column = x;// create column as you will
        column.Binding = new Binding("Value") { Source = pair};
        myDataGrid.Columns.Add(column);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagrid that allows user to change and save columns widths and
I have a datagrid that's bound to an observablecollection object. The collection may be
I have a DataGrid component that displays a few columns of data. It has
i have a datagrid that displays long text on couple columns. I have set
Hi I have a datagrid that has a number of datagridtemplate columns that are
I have a DataGrid that has between 4-10 columns. I want the columns to
I have implemented a DataGrid that way: <DataGrid x:Name=MyDataGridFilter ItemsSource={Binding} IsSynchronizedWithCurrentItem=True AutoGenerateColumns=False> <DataGrid.Columns> <DataGridTemplateColumn
I have a wpf datagrid that has it's columns generated dynamically in code and
I have a flex datagrid that I would like to remove contents from after
I have a datagrid that displays items with two columns of text row data

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.