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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:57:08+00:00 2026-06-08T10:57:08+00:00

I created a datagrid(drag and drop) in a wpf application. I then went through

  • 0

I created a datagrid(drag and drop) in a wpf application. I then went through the properties window to add the columns manually.

I want to now add rows to this datagrid through my code behind. I would have thought you would make a

DataGridRow row = new DataGridRow();

and then through maybe a Items.Add() or something you would add your values(one for each column).

I am not seeing this so I am wondering how do I do this.

I know I should be like databinding and stuff but I new to wpf and I am making a quick and dirty application and I rather just go with a forloop and make the rows manually.

I rather come back and refactor the area if I ever feel the desire too. I really just want what I am making up and running so I can use it asp.

  • 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-08T10:57:09+00:00Added an answer on June 8, 2026 at 10:57 am

    One row is one object, the values are the properties on said object. You should not create the container (the DataGridRow) yourself, the DataGrid can do that for you. Just add the data object directly to the Items (or a collection set as ItemsSource, it should implement INotifyCollectionChanged (e.g. ObservableCollection<T>)). The columns should bind the properties on the data object, by default they are created automatically from the data.


    In response to a comment: Using the DisplayNameAttribute you can get the spaces out of the headers easily but you need to add the attribute to all the offending properties:

    [DisplayName("Full Name")]
    public string FullName { get; }
    

    Then subscribe to DataGrid.AutoGeneratingColumn (- oh, there’s a hacky solution for this problem in the docs -):

    private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        var descriptor = (MemberDescriptor)e.PropertyDescriptor;
        //Takes the value from the attribute if exists & non-default-value, else property name.
        e.Column.Header = descriptor.DisplayName;
    }
    

    The hard way would be an algorithm which just splits the existing header strings correctly (would need to consider pascal casing, numbers and abbreviations, probably not so easy to get 100% accuracy).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating window application basic. As i have created datagrid with 2 columns
I have created a datagrid in ActionScript class and I want to add an
I have DataGrid with explicitly created columns in code. I am binding WPF element
I have created WPF MVVM application, and set WPFToolkit DataGrid binding to DataTable so
I create DataGrid Columns with Binding (where i is a Int value): dataGrid.Columns.Add(new DataGridTextColumn
I have the following scenario, I want to create a DataGrid and then populate
I created a new DataGridCell style for my wpf datagrid (Red Border brush). When
I have created a checkbox column in a WPF DataGrid, and I have set
I have created a sample silverlight application and trying to populated DataGrid with Data
I created an application to show a datagrid with a custom column in Flex

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.