mHelpMe
mHelpMe

Reputation: 6668

datagrid binding to an property not working

I have a datagrid where a user can enter some data. Once they have entered the data they click a button to upload the data. However I am having some issues with the data not binding as I expect.

The datagrid is bound to a list called HldLogEQ of type ObservableCollection HoldingLogEQ.

When I debug before the data is uploaded the ISIN and Sedol properties are both null which is incorrect. I thought the line below was the correct way to bind the data? What am I missing?

<DataGridTextColumn Header="Sedol" IsReadOnly="False" Binding="{Binding Security.Sedol, Mode=TwoWay}"/>

HoldingLoq Class

 public class HoldingLogEQ : INotifyPropertyChanged
    {           
        public DateTime DateEffective
        {
            get
            {
                return _dateEffective;
            }
            set
            {
                _dateEffective = value;
                OnPropertyChanged("DateEffective");
            }
        }
        public SecruityID Security
        {
            get
            {
                return _security;
            }
            set
            {
                _security = value;
                OnPropertyChanged("Security");
            }
        }           
        public List<Fund> Funds
        {
            get
            {
                return _funds;
            }
            set
            {
                _funds = value;
                OnPropertyChanged("Funds");
            }
        }

        private DateTime _dateEffective;
        private SecruityID _security = new SecruityDescriptive();
        private List<Fund> _funds;

        public event PropertyChangedEventHandler PropertyChanged;

        void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

Security Id class

public class SecurityID : INotifyPropertyChanged
    {
        public string ISIN
        {
            get
            {
                return _isin;
            }
            set
            {
                _isin = value;
                OnPropertyChanged("ISIN");
            }
        }
        public string Sedol
        {
            get
            {
                return _sedol;
            }
            set
            {
                _sedol = value;
                OnPropertyChanged("Sedol");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private string _isin;
        private string _sedol;
        #endregion
    }

Datagrid

<DataGrid Grid.Row="1"
                              x:Name="dgHldRGHTS" 
                          ItemsSource="{Binding HldLogEQ, UpdateSourceTrigger=PropertyChanged}"
                          Style="{StaticResource DataGridTemplate1}"
                          ColumnHeaderStyle="{StaticResource DG_ColumnHeaderCenter1}"                                            
                          RowStyle="{StaticResource DG_Row1}"
                          CellStyle="{StaticResource DG_Cell1}"                                    
                          RowHeaderStyle="{StaticResource DG_RowHeader1}"
                          RowDetailsTemplate="{StaticResource DG_RowDetail}" 
                          AutoGenerateColumns="False"
                          HorizontalAlignment="Stretch"                           
                          Background="Silver" 
                          Margin="50,0,50,50"                              
                          CanUserDeleteRows="True"
                          CanUserAddRows="True"
                          RowHeaderWidth="30">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Date Effective" IsReadOnly="False" Binding="{Binding DateEffective, StringFormat={}\{0:dd-MMM-yy\}, Mode=TwoWay}" MinWidth="75"/>
                            <DataGridTextColumn Header="ISIN" IsReadOnly="False" Binding="{Binding Security.ISIN, Mode=TwoWay}" MinWidth="75"/>
                            <DataGridTextColumn Header="Sedol" IsReadOnly="False" Binding="{Binding Security.Sedol, Mode=TwoWay}" MinWidth="75"/>
                            <DataGridTextColumn Header="Name" IsReadOnly="False" Binding="{Binding Security.Name, Mode=TwoWay}" MinWidth="200"/>
                        </DataGrid.Columns>
                    </DataGrid>

Upvotes: 0

Views: 322

Answers (1)

Artyom Shmarlovsky
Artyom Shmarlovsky

Reputation: 51

Maybe need add Path.

Binding="{Binding Path=Security.Sedol, Mode=TwoWay}"

Upvotes: 1

Related Questions