0

I'm using MVVM pattern to develop a WPF application. I want to display dynamic columns to DataGrid from Datatable.

I have added code to display it but it is not working. Datatable is filled with data but In datagrid , data is not displaying.

XAML:

 <DataGrid Grid.Row="1" AutoGenerateColumns="False" GridLinesVisibility="All" Foreground="Black" ItemsSource="{Binding ItemSource, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"  IsReadOnly="True" />

ViewModel:

private DataView _itemSource;

public DataView ItemSource
{
    get { return _itemSource; }
    set
    {
        _itemSource = value;
        OnPropertyChanged("ItemSource");
    }
}

public async Task PopulateData(string queryText)
{
    var dt = await CustomReportQueryDAO.GetCustomReportQueryResult("select * from [Person]");
    ItemSource = dt.DefaultView;
}         

1 Answer 1

1

You have set AutoGenerateColumns="False" on the DataGrid and you have not defined any columns.

Try changing to AutoGenerateColumns="True"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.