0
我在c#中用WPF 4.0和一个数据网格创建了一个小应用程序。 我的数据网格绑定到某些“数据表”组件的数据成员CAST DataGridView错误
我想在输入一行后做一些测试,所以我使用RowEditEnding事件。
这里是我的代码
private void dataGrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
TableCompte Compte = e.Row.DataContext as TableCompte;
if (Compte != null)
{
// Verifs
}
}
我的问题是我的目标 “孔特” 为空。
不过,我的“DataContext”价值很不错!所以这是一个演员错误,但我的错误在哪里?
这里是我的XAML声明:
<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>
感谢很多:)
调试器?检查'e.Row.DataContext'? –
什么是dataGrid1的ItemsSource?它是一个数据表? –
e.row.dataContext是正确的!这就是为什么我知道这是一个Cast Error。 –