Skip to main content

Bind DataGrid using Entity framework (EDMX model) in wpf

In this article we will learn how to bind DataGrid using EDMX file in wpf. I already bind dataGrid in window form using EDMX. In both article, i notice that only one difference between both that is xaml file. Lets to start to design this in wpf:

<Window x:Class="SplashSCreen.bindgridpanel"
        Title="bindgridpanel" Height="300" Width="300">
        <DataGrid AutoGenerateColumns="False" ColumnWidth="*" x:Name="dataGrid" HorizontalAlignment="Left" Margin="54,56,0,0" VerticalAlignment="Top" Height="178" Width="173">
                <DataGridTextColumn Binding="{Binding Emp_Id}" Header="Emp_Id" />

                <DataGridTextColumn Binding="{Binding Emp_Name}" Header="Emp_Name" />


Above mentioned code define the binding structure. I have one dataGrid control in the window. x:Name is a property of each control which is define the class instance , through which we can access other property of control in business logic. I have two Text column in dataGrid which take two attribute first one is Binding and another one is Header. Header represent the DataGrid column name and binding define the actual name of database table column's name.

Note : Before going to code behind must to add EDMX file in the project.

using System.Linq;
using System.Windows;

namespace SplashSCreen
    /// <summary>
    /// Interaction logic for bindgridpanel.xaml
    /// </summary>
    public partial class bindgridpanel : Window
        TutorialEntities TE = new TutorialEntities();
        public bindgridpanel()

        private void loadgrid()
            var data = from d in TE.emps select d;
            dataGrid.ItemsSource = data.ToList();

Code generate the following output

Bind DataGrid using Entity framework (EDMX model) in wpf

After add the edmx file in the project , you can access the public property of context class (here i have 'emps'). Through which we can apply operation on dataGrid. 


Popular posts from this blog

difference between structure and union in C Language

In c language article we will see the difference between union and structure. Both are the user define datatype in c language. See the table which is mentioned below: ASP.NET Video Tutorial Series Structure Union1.The keywordstruct is used to define a structure 1. The keyword union is used to define a union. 2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum ofsizes of its members. The smaller members may end with unused slack bytes. 2. When a variable is associated with a union, thecompiler allocates thememory by considering the size of the largest memory. So, size of union is equal to the size of largest member. 3. Each member within a structure is assigned unique storage area of location. 3. Memory allocated is shared by individual members of union. 4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset v…

Difference between Linear search and Binary Search in c language

SQL Video Channel : Download all SQL Video

Binary Search Linear Search Works only on sorted items. such as  1,2,3,4,5,6  etc
Works on sorted as well as unsorted items. 12,4,5,3,2,1 etc Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such as Suppose your list items are : 12,3,4,5,1 and you want to search 12 number then you get beginning in the list. Works well with arrays and not on linked lists. Works with arrays and linked lists.
Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.

Memory representation of Linked List Data Structures in C Language

Memory representation of Linked List

             In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.

               Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:

      Suppose next node is allocated at an address 506, so the list becomes,

  Suppose next node is allocated with an address with an address 10,s the list become,

The other way to represent the linked list is as shown below:

 In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of next node. The last node …