Click here to Skip to main content
11,709,536 members (57,265 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: WPF Framework entity

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
Edited 28-May-12 23:47pm
db7uk at 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 at 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
0 Sergey Alexandrovich Kryukov 525
1 OriginalGriff 250
2 Peter Leow 219
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 29 May 2012
Copyright © CodeProject, 1999-2015
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