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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:08:07+00:00 2026-05-23T00:08:07+00:00

I’m populating datagrid with collection of anonymous types (I’m setting DataGrid’s DataContext property). And

  • 0

I’m populating datagrid with collection of anonymous types (I’m setting DataGrid's DataContext property). And there are no errors. And nothing dsiplayed in datagrid. I’ve tried to make the same with defined object collection, but again nothing is displayed. Please could you instruct me what to do.

Thanks!

EDIT 1

Ok. I tried to set ItemsSource property and it works. But I’m getting strange result..

enter image description here

EDIT 2

I don’t know how but after 3d launch it now’s working properly?

private void ShowABCResultsButtonOnClick(Object sender, RoutedEventArgs e)
{
    var anonArray = new List<NormalizedResult> 
    { 
        new NormalizedResult
        { 
            Key = 1,
            Title = "Колос", 
            Volume = 1322.01m,
            Weighted = 6.7840m,
            Result = 6.7840m,
            Group = "A"
        },
        new NormalizedResult
        { 
            Key = 2,
            Title = "Украинский Новый", 
            Volume = 1250.47m,
            Weighted = 6.4169m,
            Result = 13.2009m,
            Group = "A"
        },
        new NormalizedResult
        { 
            Key = 3,
            Title = "Ржано-Пшеничный", 
            Volume = 1202.1m,
            Weighted = 6.1687m,
            Result = 19.3695m,
            Group = "A"
        }
    };

    this.dataGrid2.ItemsSource = anonArray;
}

this is my code.

And again I’ve launched.. and it displayed properly only the third time?



  • 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-23T00:08:08+00:00Added an answer on May 23, 2026 at 12:08 am

    You likely need to do two things. The first, as @Tim suggested, is assign the query to the DataGrid.ItemsSource property.

    myDataGrid.ItemsSource = from a in x
                             select new { Prop1 = a.A, Prop2 = a.B, ... };
    

    The second bit will be to enable automatic column generation on your DataGrid:

    <DataGrid x:Name="myDataGrid"
              AutoGenerateColumns="True" />
    

    Edit: I’ve recreated your picture using automatic column generation and anonymous types with a vanilla LINQ query. So you will need to be could use explicit columns to use or switch to a real type.

    <DataGrid x:Name="myDataGrid"
              AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Property 1"
                                Binding="{Binding Prop1}"/>
            <DataGridTextColumn Header="Property 2"
                                Binding="{Binding Prop2}"/>
        </DataGrid.Columns>
    </DataGrid>
    

    Edit 2: You CAN use AutoGenerateColumns="True" just not with the bare IEnumerable<T> where T is an anonymous type. By adding ToList the problem goes away.

    myDataGrid.ItemsSource = (from m in typeof(int).GetMethods()
                              select new
                              {
                                  Name = m.Name,
                                  ReturnType = m.ReturnType.FullName
                              }).ToList();
    

    XAML then goes back to:

    <DataGrid x:Name="myDataGrid"
              AutoGenerateColumns="True" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.