Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF Framework entity
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...
Posted 28-May-12 23:04pm
Edited 28-May-12 23:47pm
v3
Comments
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 676
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,198
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,470


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 29 May 2012
Copyright © CodeProject, 1999-2014
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