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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:03:11+00:00 2026-05-23T18:03:11+00:00

I have a WPF application with two DataGrids that share the same ItemsSource. When

  • 0

I have a WPF application with two DataGrids that share the same ItemsSource. When I set one of the DataGrid’s IsReadOnly property to true, I lose the ability to add records to the other DataGrid. I can still edit the contents of the second datagrid, but just cannot add records.

Is this intended? Is there way around this? I could use IsEnabled=”False” for the DataGrid, but I then lose the ability to scroll in it.

Here is the setup:

XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <DataGrid Name="dgA" Grid.Row="0" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTextColumn Header="FirstName" Binding="{Binding Path=FirstName}" />
            <DataGridTextColumn Header="LastName" Binding="{Binding Path=LastName}" />
        </DataGrid.Columns>         
    </DataGrid>
    <DataGrid Name="dgB" Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True">
        <DataGrid.Columns>
            <DataGridTextColumn Header="FirstName" Binding="{Binding Path=FirstName}" />
            <DataGridTextColumn Header="LastName" Binding="{Binding Path=LastName}" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

C#:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        List<Person> persons = new List<Person>();
        persons.Add(new Person() { FirstName = "Bob", LastName = "Johnson" });
        persons.Add(new Person() { FirstName = "John", LastName = "Smith" });

        dgA.ItemsSource = persons;
        dgB.ItemsSource = persons;
    }

    class Person
    {
        public Person() { }

        public string FirstName
        {
            get;
            set;
        }

        public string LastName
        {
            get;
            set;
        }
    }
}
  • 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-23T18:03:12+00:00Added an answer on May 23, 2026 at 6:03 pm

    I think what’s going on is that the IsReadOnly property is making the DataGrid readonly through the DefaultView for persons, and since this DefaultView will be the same for both of your DataGrid's, both looses the ability to add new rows.

    Both doesn’t become readonly however (as you said in your question) so I’m not sure if this is a bug or a desired behavior.

    I’m also not sure what’s going on behind the scenes here that causes this behavior but you can verify that the CollectionView’s are the same through the debugger (since the CollectionView property is private). The following three statements come out as true

    dgA.Items.CollectionView == CollectionViewSource.GetDefaultView(persons) // true
    dgB.Items.CollectionView == CollectionViewSource.GetDefaultView(persons) // true
    dgA.Items.CollectionView == dgB.Items.CollectionView // true
    

    You can get it to work the way you like by changing the List to an ObservableCollection and use separate ListViewCollection's for your DataGrid's

    public MainWindow()
    {
        InitializeComponent();
    
        ObservableCollection<Person> persons = new ObservableCollection<Person>();
        persons.Add(new Person() { FirstName = "Bob", LastName = "Johnson" });
        persons.Add(new Person() { FirstName = "John", LastName = "Smith" });
    
        dgA.ItemsSource = new ListCollectionView(persons);
        dgB.ItemsSource = new ListCollectionView(persons);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a WPF Application that has a two flavors with a consistent UI
I have an Application with two Tabs in WPF. One is Used to add
I have a WPF application with two PasswordBoxes, one for the password and another
I have two different applications using the same aspnetdb database - a WPF application
I have a DataGrid that two of its columns are ComboBoxes (one contains few
I have two different ways of displaying items in a WPF application. The first
I have WPF Application where I have One main form and other user controls
I have a WPF application that runs fine under XP as an administrator. When
I have a WPF application (.NET 3.0, VS2008) that displays data in a tab
I have a wpf application (C#) that needs to copy a file to a

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.