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

  • Home
  • SEARCH
  • 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 9240603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:13:03+00:00 2026-06-18T08:13:03+00:00

I am using would like to use WPF DataGrid to display a list of

  • 0

I am using would like to use WPF DataGrid to display a list of instances of e.g. a class Animal that I store during the life of my application (say I add/remove animals to my list) in an attribute of my main Window

public List<Animal> _animals
public class Animal {
    public int ID { get; set; }
    public strng name { get; set; }
}

I added the DataGrid to my XAML as such

<DataGrid Name="AnimalGrid"></DataGrid>

Then linked it to a function LoadAnimals() when initializing my window :

AnimalGrid.ItemsSource = LoadAnimals();
public List<Animal> LoadAnimals() {
    return _animals;
}

I want the Data grid to update/refresh. More precisely I pretty much only want the data grid to call LoadAnimal function again. I have tried AnimalGrid.Items.Refresh()but it does not work.

Any suggestions ?

  • 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-18T08:13:04+00:00Added an answer on June 18, 2026 at 8:13 am

    WPF bindings don’t work by magic alone, the code somehow needs to emit the right events for the data grid to update.

    To update in response to changes in the collection (additions / deletions), use ObservableCollection<Animal> as your ItemsSource, that will fire the proper events to update the data grid when the collection changes.

    You will also have to implement INotifyPropertyChanged in your Animal class if you want the grid to respond to changes in the ID and name properties for the individual rows.

    Also, your LoadAnimals() function doesn’t seem to do anything, since it just checks for null and then returns null in that case. +1 for the comment about MVVM, it is better in the long run to bind your ItemsSource to some property in a class (view model) instead of setting it in the code behind.

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

Sidebar

Related Questions

I would like to use the syntax that printf uses, using the %d, %s
I'm using the CCNode class in cocos2d and would like to use its schedule:interval:
I'm using WPF I would like that my windows take the entire screen of
I display images in my WPF app using BitmapImage . However, I would like
Using the SplitButton from exceed's extended wpf toolkit , I would like to use
I would like to use D3.js (or maybe Raphaël ) for backend-generated reports using
I would like to use the group_by method, but instead of using a column
I'm using SQL Server 2008 and I would like to use a sproc to
I'm using the following code successfully with HTTP but I would like to use
I am using the java MongoDB driver for gridfs and would like to use

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.