I have a code sample using Entity Framework that saves changes when leaving a cell in a DataGrid.
WPF/Entity Framework Core primer (C#)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I use C# WPF and Entity Framework DB First
I have a Database in SQL Server 2014
I want to save (Insert, Update , Delete) my data in my table but I want to do it directly in DataGrid not using TextBox
I want to be like Microsoft Excel Data Entry
I tried this in CellEndEdit :
private void DGR_Formy_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (DGR_Formy.SelectedItem != null && DGR_Formy.SelectedItems != null)
{
var DtValue = DGR_Formy.ItemContainerGenerator.ItemFromContainer(e.Row);
var WhatValue = string.Empty;
FrameworkElement element_1 = DGR_Formy.CurrentColumn.GetCellContent(e.Row);
//string selectedColumnHeader = (string)DGR_Formy.SelectedCells[0].Column.Header;
if (element_1.GetType() == typeof(TextBox))
{
WhatValue = ((TextBox)element_1).Text;
}
Telbook LocationTel = (Telbook)DGR_Formy.SelectedItem;
//Int64 MyID = Convert.ToInt64(dbms.Telbook.Where(t => t.ID.Equals(LocationTel.ID)).FirstOrDefault());
Telbook telbook = new Telbook()
{
ID = LocationTel.ID,
Name = WhatValue,
Tel = LocationTel.Tel
};
dbms.SaveChanges();
//dbms.Entry(telbook).State = telbook.ID == 0 ? EntityState.Added : EntityState.Modified;
}
}
I know this code is wrong it's just sample What I tried not !
so my problem is I don't know the code
What I need:
In DataGrid Detect What is Changed and Save it (Insert, Update, Delete) in the best performance
Thanks for taking your time to help me
I have a code sample using Entity Framework that saves changes when leaving a cell in a DataGrid.
WPF/Entity Framework Core primer (C#)
What you need to do is learn MVVM. If you use that then each cell is bound to a property in a ViewModel. When it changes you get notified in the property set. This is the proper way to do things in WPF.