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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:54:52+00:00 2026-05-28T04:54:52+00:00

I am trying to figure out the reason behind why the datatable acts differently

  • 0

I am trying to figure out the reason behind why the datatable acts differently when assigning a list/array to it.

MainDisplay = An empty dockpanel.

LItem = A class with 2 properties, Id and Data

var dgBills = new DataGrid();
dgBills.ItemsSource = new List<ListBillsItem>
{
    new LItem {Id = 5, Data = "Patrik"},
    new LItem {Id = 6, Data = "Thomas"}
};
MainDisplay.Children.Add(dgBills);

This produces a datagrid with 3 rows!? One row for Patrick, one for Thomas and one (last) empty row.

If i change it into this, then it produces only 2 rows (as it should)

var dgBills = new DataGrid();
dgBills.ItemsSource = new[]
{
    new LItem {Id = 5, Data = "Patrik"},
    new LItem {Id = 6, Data = "Thomas"}
};
MainDisplay.Children.Add(dgBills);

Anyone that can explain why it behaves like this? I am getting a list back from the database and i would like it to only display the records that are in the list.

  • 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-28T04:54:52+00:00Added an answer on May 28, 2026 at 4:54 am

    This is due to the property CanUserAddRows="True" on the datagrid that show you an empty row for the new item, if the underlying collection accepts new items. Put this property to false and you should see the same in the two case.

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

Sidebar

Related Questions

I'm trying to figure out the reason behind some regex comparison results I'm getting
For some reason that I've been trying to figure out, the links on my
When trying to figure out if a string is null or empty, I usually
I'm trying to figure something out, but can't seem to find the reason why,
Trying to figure out a rather annoying IE7 CSS issue. For some strange reason
For some reason, I am having a mental block trying to figure out how
Trying to figure out an equation to get the current group a page would
Trying to figure out the best way to set up collection lists for users
Trying to figure out which to use.
Trying to figure out how to programmatically access the web pages in the application.

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.