I have created a little apps in c# with WPF 4.0 and a datagrid. My datagrid is bound to somes data members of a "TableCompte" Object
I would like to make some test after a line entered, so, i use the RowEditEnding event.
Here is my code
private void dataGrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
TableCompte Compte = e.Row.DataContext as TableCompte;
if (Compte != null)
{
// Verifs
}
}
My problem is my object "Compte" is null.
Nevertheless, my "DataContext" Value is good ! So it's a cast error, but where is my error?
Here is my XAML declaration :
<DataGrid AutoGenerateColumns="false" Name="dataGrid1" AreRowDetailsFrozen="false" Margin="31,227,28,82" RowEditEnding="dataGrid1_RowEditEnding">
<DataGrid.Columns>
<DataGridTextColumn Width="134" Header="Compte d'origine" Binding="{Binding Path=m_CompteOrigine, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Width="134" Header="Compte Taux 1" Binding="{Binding Path=m_CompteTaux1, Mode=TwoWay ,UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Width="134" Header="Taux 1" Binding="{Binding Path=m_Taux1, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged }" />
<DataGridTextColumn Width="134" Header="Compte Taux 2" Binding="{Binding Path=m_CompteTaux2, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Width="134" Header="Taux 2" Binding="{Binding Path=m_Taux2, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged }" />
<DataGridTextColumn Width="134" Header="Compte Taux 3" Binding="{Binding Path=m_CompteTaux3, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Width="134" Header="Taux 3" Binding="{Binding Path=m_Taux3, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged }" />
</DataGrid.Columns>
</DataGrid>
Thanks a lot :)