Search code examples
c#wpfwpfdatagrid

DataGrid is not show the data instead its show Model Class Name


When I bind the data collection to my data grid its not show the data instead of data it show the model class name how many row i have that much of time. I tried the normal WPF Data Grid and Dev Express Data Grid both but anything is not working to me.

XAML:

Using WPF DataGrid

 <DataGrid ItemsSource="{Binding EmpDetails}" AutoGenerateColumns="True"/>

Using Dev Express DataGrid

 <dxg:GridControl ItemsSource="{Binding EmpDetails}" AutoPopulateColumns="True" AutoGenerateColumns="AddNew" >
                            <dxg:GridControl.View>
                                <dxg:TableView />
                            </dxg:GridControl.View>
                        </dxg:GridControl>

I have 2 record in my collection please find below image

https://i.sstatic.net/pdjQt.jpg

Dev Express DataGrid run time Image:

https://i.sstatic.net/Iq9VC.jpg

WPF DataGrid run time Image:

https://i.sstatic.net/HMgd8.png

Thanks for your spending time to my question.


Solution

  • Put the EmployeeDetails is Observable Collection and All the Columns of the table write as the Property with OnPropertyChange include the Model Class.

    EX:

    private string firstName;
    public string FirstName
    {
     get {return firstName;}
     set { firstName = value; OnPropertyChange("FirstName");}
    }