Click here to Skip to main content
12,892,709 members (45,653 online)
Rate this:
Please Sign up or sign in to vote.
See more: WPF entity-framework

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..
                  <Style TargetType="{x:Type DataGridRowHeader}">
                      <Setter Property="Content" Value="{Binding Converter={StaticResource RowIndexConverter }}"/>

The Converter Code is
public object Convert(object value, Type targetType, object parameters, System.Globalization.CultureInfo culture)

                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 it didn't showing any 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...
Posted 28-May-12 23:04pm
Updated 28-May-12 23:47pm
db7uk 29-May-12 8:55am
The binding to the datagrid will (depending on the datasource property value) have the bound object in it (i.e. MyOrg.EmployeeDetails). The reason this is showing up in the converter is because you bound the content of the header to your entity.

What are you trying to achieve? do you want a label that has the number of rows in the grid?

If so can you not bind to the count of your collection instead of using a converter?
V G S Naidu A 29-May-12 23:53pm
Actually i want to display row number before the in header,,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 29 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100