C# Programming (Intermediate) - Lecture 8: DataGrid Binding to Entity Framework for Automatic Saving

preview_player
Показать описание
C# Programming (Advanced/Intermediate) Lectures (8/14) will teach you #CSharp #programming from beginner to intermediate/expert level. This course is an excellent source to learn advanced concepts in C# #coding. If you are a beginner to C#, watch our previous course lectures. The playlist link of the previous course is below.

Full playlist of the previous course: C# For Beginners ⤵️

Technology Playlist (30+ Tutorial / Guide / News / Review Videos) ⤵️

Stable Diffusion Playlist (30+ Tutorial / Guide Videos) ⤵️

Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.

Full playlist of this course ⤵️

You can watch for free our C# Programming, ASP .NET Core MVC programming, Machine Learning and Software Engineering related courses on our playlists page ⤵️

GitHub code repository of this course (source codes of the lectures) ⤵️

In lecture 8:
* We have coded a drugs editing screen with DataGrid
* How to bind DataGrid to an entity framework context with local binding
* How to bind track changes of a DataGrid and save them in the database (add, update, delete and insert)
* How to fire DataGrid cell modified event and display unsaved add/update/delete/insert changes
* How to get anonymous/custom type results from entity framework select queries
* How to properly refresh a DataGrid bound to an entity framework context
* How to cast IList objects into a custom class objects list
* Know how to search your problem and find answers

Introduction

DataGrid is a commonly used control in many software applications. It is a versatile tool that allows developers to display data in tabular form, as well as edit, sort, and filter that data. In this article, we will discuss how to create a drugs editing screen using DataGrid. We will also cover topics such as binding DataGrid to an Entity Framework context with local binding, tracking changes, firing cell modified events, displaying unsaved changes, getting anonymous/custom type results, refreshing DataGrid, and casting IList objects to custom class objects.

DataGrid and Entity Framework

The DataGrid control is a powerful tool for displaying and editing data in a tabular format. The Entity Framework is an object-relational mapping (ORM) framework that allows developers to work with databases using .NET objects. These two tools work seamlessly together to provide developers with an efficient way to display and edit data.

Binding DataGrid to an Entity Framework Context with Local Binding

To bind DataGrid to an Entity Framework context, we need to use local binding. Local binding means that the data is stored in memory, and any changes made to it are not immediately saved to the database. Instead, we must manually save the changes to the database.

To bind DataGrid to an Entity Framework context with local binding, we need to first create an Entity Framework context object. This object represents a connection to the database and provides access to the data.

Once we have our Entity Framework context object, we can then create a local binding between the DataGrid control and the context object. This is done by setting the DataGrid's ItemsSource property to the result of a LINQ query that retrieves the data we want to display.

Tracking Changes and Saving Them in the Database

When working with DataGrid, it is important to track any changes made to the data. This includes adding, updating, deleting, and inserting records. To track changes, we can use the DataGrid's CellEditEnding event. This event fires when the user finishes editing a cell in the DataGrid.

Inside the CellEditEnding event, we can determine what type of change was made to the data and update our Entity Framework context accordingly. For example, if a new record was inserted, we can add it to the context using the Add() method. If an existing record was updated, we can update it using the context's Update() method.

Once we have made changes to our Entity Framework context, we need to save those changes to the database. This is done by calling the context's SaveChanges() method.

Firing DataGrid Cell Modified Event and Displaying Unsaved Changes

In addition to tracking changes, we can also fire a DataGrid CellModified event when the user modifies a cell. This event allows us to display unsaved changes to the user.

To fire the CellModified event, we can use the DataGrid's CellValueChanged event.
Рекомендации по теме
Комментарии
Автор

Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.

SECourses
Автор

I learned these in the lesson

-How do we disable a buton?
-How do we connect DataGrid to database with Entity FrameWork?
-How do we make the refresh button and custom column naming for DataGrid
-How do add, change, delete in DataGrid?
-How do we hide auto-generated columns in DataGrid?
-How can we find and show event and unsaved event in DataGrid?

Thank You For Lesson
195050019

yunusemrebitkay
Автор

In this lesson I learned:
- refresh and save values in datagrid.
- delete selected row
- delete unnecessary spaces in datagrid.
- set the columns to equal length.

Number:195050005

samedarc
Автор

In this video i learned
-connecting DataGrip to database
-Add, change, delete from DataGrid
-Link datagrid with entity framework
-generating extra column automatically

195050012

dodontkar
Автор

In this lesson I learned that:
How to bind from SQL table to datagrid
- How to Refresh datagrids
- Add, Change and Delete from datagrid
- Link datagrid with entity framework
-Generating extra column automatically
Thanks for the lesson
Student ID:195050808

feritbarbur
Автор

In this lesson we learnd :

*connect DataGrid to database
*make the refresh button
*add, change, delete in DataGrid
*hide auto-generated columns
*find and show event

Number : 195050023

batuhancanbulat
Автор

I've learned from video:
- save Datagrid changes
- add button in data grid view
- datagrid refresh items source from entity framework
- fix Datagrid not update when the item change
- refresh context
- add a fake column to linq entity
- creat blinding list
- entity framework

Amro Duveydari
School Number: 195050905

amroduveydari
Автор

in this video we learned
composing Drugs section(dataGrid, buttons)
saving and updating data in dataGrid
add button wpf dataGrid
creating anonymous type itemsource
deleting selected item button
generating extra column automatically
195050014

nisa
Автор

I have learned:
1- How to bind from SQL table to datagrid
2- How to Refresh datagrids
3- Add, Change and Delete from datagrid
4- Link datagrid with entity framework

205060911
MHD OMAR DAK ELBAB

mhdomardakelbab
Автор

in this lecture, i learned;

- Editing screen with DataGrid
- Bind DataGrid to an entity framework context with local binding
- Bind track changes of a DataGrid and save them in the database (add, update, delete and insert)
- Fire DataGrid cell modified event and display unsaved add/update/delete/insert changes
- Anonymous/custom type results from entity framework select queries
- Properly refresh a DataGrid bound to an entity framework context



-195050803
AHMET MUSTAFA VİDİN

ahmetvidin
Автор

In this lecture ;
connecting DataGrip to database and save it
creating anonymous itemsource
Generating extra column automatically
195050021

yusufcan
Автор

205060021
From this lecture I have learned:
-How to add the prescriptions and medicines to our Project using DataGrid
-How save changes made in DataGrid into the database (changes such as: update, insert, add, and delete)
-How to show changes made in DataGrid that are not saved (changes such as: update, insert, add, and delete)
-How to correctly refresh a DataGrid attached to to an entity framework
-How to put IList objects into a custom class objects list

halimeince
Автор

205060017
I learned:
- refresh and save values in datagrid.
- delete selected row
- delete unnecessary spaces in datagrid.
- set the columns to equal length.

esiladeniz
Автор

195050013
lecture 8
-automatic save
-update delete insert methods
-saving data grid
-refresh data Grid etc.

muhammedmustafakapici
Автор

In this course ı will learnd;
- Find de DataGrid
- Delete selected
- Refresh DataGrid
- Save DataGrid
- I will use DataGrid
- Change DataGrid
- Connect DataGrid to database with EF power
BATUHAN KESKİN
195050029

batuhankeskin
Автор

195050016
Koray İnci

I the video we learned
-How to do datagrid bindings
-Saving and refreshing datagrid's items
-How to add, delete or change items of datagrid
-Getting anonymous results from entity framework
-DataGridView
-What is auto generated column datagridview row

Thanks for the lesson.

korayinci
Автор

You talked about screen editing with DataGrid, data binding with entity on datagrid, update delete insert update on datagrid to database, Anonymous/custom type results from entity framework select queries, datagrid refresh.


Number: 195050026

recepgunes
Автор

DataGrid
Binding DataGrid to an entity framework context
binding tracking changes of a DataGrid
How to fire DataGrid cell modified event and display unsaved add/update/delete/insert changes
getting Annonymous/custom type results from entity framework select queries
refreshing DataGrid bound to an entity framework context
how to search for the problem and finding answers

205060904

nouryalsukhni
join shbcf.ru