mHelpMe
mHelpMe

Reputation: 6668

Datagrid only returning empty rows

I have a datagrid in my C# app. When the application is loaded I see that the datagrid has no rows which is correct as no data has been loaded. The user can then click a button to load some data. This data should be reflected in the datagrid but it is not. All that happens is 12 empty rows are visibile. The 12 empty rows is equal to the number of records I expect to see.

When I step through the code I can see my underlying object (PayOffWin) does contain data in all the fields and 12 items in the list. For some reason this data is not being reflected in my datagrid though and I cannot see what I am doing wrong.

XAML

<DataGrid Name="dgPayoffWin" Grid.Row="1" Grid.Column="0"
                        Margin="20"
                        ItemsSource="{Binding Path=PayOffWin}"
                        Style="{StaticResource dgBase}"
                        CanUserAddRows="False"
                        CanUserDeleteRows="False"                          
                        AutoGenerateColumns="false">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Range" Binding="{Binding Path=Group}" IsReadOnly="True"/>
                        <DataGridTextColumn Header="Frequency" Binding="{Binding Path=WinNum}" IsReadOnly="True"/>
                        <DataGridTextColumn Header="Total Value" Binding="{Binding Path=WinGain}" IsReadOnly="True" Width="*"/>
                    </DataGrid.Columns>
                </DataGrid>

Code Behind in my view model

 List<ResultHolder.PayOffMatrix> _payOffWin;

 public List<ResultHolder.PayOffMatrix> PayOffWin
    {
        get { return _payOffWin; }
        set
        {
            _payOffWin = value;
            OnPropertyChanged("PayOffWin");
        }
    }


public class PayOffMatrix
        {
            public enumOutCome OutCome;
            public string Group;
            public double LimitUp, LimitDown;
            public double WinNum, WinGain, LossNum, LossGain;
            public double WinProb, WinExpect, LossProb, LossExpect;
        }

Upvotes: 0

Views: 269

Answers (2)

blindmeis
blindmeis

Reputation: 22445

you can just bind to PUBLIC PROPERTIES so just change your fields in PayOffMatrix into public properties

Upvotes: 1

NTinkicht
NTinkicht

Reputation: 1002

Change:

List<ResultHolder.PayOffMatrix> PayOffWin;

to:

ObservableCollection<ResultHolder.PayOffMatrix> PayOffWin;

It will work, Lists dont Notify to the view Automaticaly.

Upvotes: 1

Related Questions