Hi,
I am using EntityFrameWork while working with Wpf application , In that iam using the DataGrid, In that i am trying to display the Numbers for each Row to that DataGrid... For that i have used one converter and RowHeaderStyle Code... But it showing some convertion error... the Detailed Code is Like Below..
<DataGrid.RowHeaderStyle>
<Style TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Content" Value="{Binding Converter={StaticResource RowIndexConverter }}"/>
</Style>
</DataGrid.RowHeaderStyle>
</DataGrid>
The Converter Code is
public object Convert(object value, Type targetType, object parameters, System.Globalization.CultureInfo culture)
{
try
{
System.Data.DataRowView drv = (System.Data.DataRowView)value;
DataGrid dg = (DataGrid)Application.Current.MainWindow.FindName("GridEmployeeList");
CollectionView cv = (CollectionView)dg.Items;
int rowIndex = cv.IndexOf(drv) + 1;
return rowIndex.ToString();
}
catch (Exception e)
{
throw new NotImplementedException(e.Message);
}
}
While Working with Normal DataBase connection here...In Convertion function, the Type of the varible 'value' is
System.Data.DataRowView...so it didn't showing any error..it showing row count perfectly...
But when i working with EntityFrameWork and Binding Values to DataGrid ,,,In Convertion function, the Type of the varible 'value' is
showing.."MyOrg.EmployeeDetails" ..i.e it is of type Edm class, So it getting error like"Unable to cast object of type 'MyOrgDA.EmployeeDetail' to type 'System.Data.DataRowView'.""...
please provide the Solution or alternative solution to OverCome this behaviour While Working with EntityFrameWork..
The Same Code working Fine for normal Code without using EntityFrameWork...
Thank you...