List of DataGrid Not updating

40 Views Asked by At

I have a list of DataGrids. I am transferring from my list of DataTables (of selected index ) into List of DataGrids. In code, I can monitor that itemsource gets transferred Datatable but, it is not visible on the window screen. Here is my code:

m_AllDgTag[item.ID].ItemsSource = MainWindow.dataTables[item.ID].DefaultView;

Where: m_AllDgTag is my list of Datagrids

  • I have tried refresh command already but, it did not worked.
1

There are 1 best solutions below

0
Silny ToJa On

In this way without problem assign source. Maybe something is missing from your code. You can compare with it.

<DataGrid x:Name="dataGrid1" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
    </DataGrid.Columns>
</DataGrid>

public partial class MainWindow : Window
{
    public class Person
    {
        public string Name { get; set; }
    }
    List<DataGrid> dataGridsList = new List<DataGrid>();
    List<Person> per = new List<Person>();
    List<Person> per2 = new List<Person>();
    public MainWindow()
    {
        InitializeComponent();
        dataGridsList.Add(dataGrid1);
        per.Add(new Person() { Name = "a" });
        per.Add(new Person() { Name = "b" });
        dataGridsList[0].ItemsSource = per;
        per2.Add(new Person() { Name = "c" });
        dataGridsList[0].ItemsSource = per2;
        

    }
}