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

The Archive Base Latest Questions

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

I have a datagrid that is bound to a List in the view model.

  • 0

I have a datagrid that is bound to a List in the view model. The grid’s contents don’t update until I click on the row header. Clicking in various cells doesn’t affect it. I have to click on the header.

This is the datagrid in the XAML:

<DataGrid x:Name="TransactionDetailsGrid" Grid.Row="1" AutoGenerateColumns="False" SelectionMode="Extended" IsReadOnly="True" HeadersVisibility="Column"
                  ItemsSource="{Binding TransactionDetailList}" SelectedItem="{Binding SelectedTransactionDetail}" GridLinesVisibility="None">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=Account.AccountNumber}" Header="Account No." HeaderStyle="{StaticResource DataGridHeaderStyleCenter}" Width="120" />
        <DataGridTextColumn Binding="{Binding Path=Account.AccountName}" Header="Account Name" HeaderStyle="{StaticResource DataGridHeaderStyleCenter}" Width="*" />
        <DataGridTextColumn Binding="{Binding Path=Amount}"  Header="Amount" HeaderStyle="{StaticResource DataGridHeaderStyleCenter}" Width="120" />
    </DataGrid.Columns>
</DataGrid>

And this is from the view model:

public List<TransactionDetail> TransactionDetailList
{
    get { return this._transactionDetailList; }

    set
    {
        this._transactionDetailList = value;
        RaisePropertyChanged("TransactionDetailList");                
    }
}

This is the edit of one of the items, in the view model:

private void AddTransactionDetail()
{
    TransactionDetailViewModel viewModel = new TransactionDetailViewModel();

    MainWindowViewModel.ViewLoader.ShowDialog(viewModel);

    if (viewModel.TransactionDetail != null)
    {
        this.TransactionDetailList.Add(viewModel.TransactionDetail);
        RaisePropertyChanged("TransactionDetailList");
    }
}

After this runs, I can put a breakpoint on the getter of TransactionDetailList, and the collection has the item in it. However, the datagrid is empty. If I click on the header row, the item shows up in the grid.

I have the same issue when doing an edit.

I’ve done this successfully before, so I’m not sure what’s different here. Am I missing something obvious? Why won’t the grid show its contents until I click on the header row?

I just noticed something interesting. When I click on the grid header, the breakpoint in the TransactionDetailList getter doesn’t get hit, but the data still shows up. So, it’s like the grid has the info, it’s just not showing it until the header is clicked.

After changing to use ObservableCollection, it worked. But now I’m having the same problem with the edit (grid doesn’t update until clicking the header):

private void EditTransactionDetail()
{
    TransactionDetailViewModel viewModel = new TransactionDetailViewModel(this.SelectedTransactionDetail);

    MainWindowViewModel.ViewLoader.ShowDialog(new TransactionDetailViewModel(this.SelectedTransactionDetail));

    RaisePropertyChanged("TransactionDetailList");
}

Does my entity need to implement INotifyPropertyChanged? If I change the collection, and call RaisePropertyChanged, shouldn’t that cause an update to the grid?

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

    The problem is that when you add or remove an item from the collection, the setter isn’t called. This means INotifyPropertyChanged isn’t called, and the view has no way of knowing it needs to be refreshed.

    WPF solves this by also supporting the INotifyCollectionChanged interface.

    Try using an ObservableCollection<TransactionDetail> instead of a List<TransactionDetail>. ObservableCollection<T> is built in, and implements INotifyCollectionChanged, so you won’t have to do much to your code.

    Also make sure that you continue to implement INotifyPropertyChanged on your view model as you already have. This way the view will be notified when you replace the entire collection (when the setter is called).

    public ObservableCollection<TransactionDetail> TransactionDetailList
    {
        get { return this._transactionDetailList; }
    
        set
        {
            this._transactionDetailList = value;
            RaisePropertyChanged("TransactionDetailList");                
        }
    }
    

    See:

    • http://msdn.microsoft.com/en-us/library/ms668604.aspx
    • http://msdn.microsoft.com/en-us/library/ms748365.aspx (although this isn’t using MVVM style)

    Edit:

    Also, you should implement INotifyPropertyChanged on TransactionDetail too. If you can’t, wrap it in a class that does implement INotifyPropertyChanged.

    If you don’t implement it on TransactionDetail, than changes you make that don’t impact the list, but do impact properties on a TransactionDetail instance, won’t show in the UI until you somehow refresh the whole list.

    If you tried to fix this by calling RaisePropertyChanged on the list property, then your UI thinks the entire list (and hence the whole set of UI objects) needs to be thrown out and updated. This will kill your performance and make your app sluggish.

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

Sidebar

Related Questions

I have a data grid in a view that is bound to a List
I have a view with this snippet: <DataGrid AlternatingRowBackground=#FFF2F5F1 AutoGenerateColumns=False Grid.Row=0 GridLinesVisibility=None IsReadOnly=False IsSynchronizedWithCurrentItem=True
Have a List bound as the itemssource for a grid. MyObject has properties that
I have a problem with a data-bound DataGrid control, in that despite each column
Using .NET 1.1, I have a DataGrid that contains three columns for each row.
I have a custom dataGrid that acts more like a 2D list (if that
I have a datagrid that is bound to a observableCollection of Employees The user
I have a data grid that looks like this <tk:DataGrid ItemsSource={Binding Parents} AutoGenerateColumns=False> <tk:DataGrid.Columns>
I have a List<T> collection which is bound to a DataGrid. T is some
I have a bound DataGrid and various other controls(external to the datagrid) that show

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.