Help, please, what could be the matter. When the focus is lost, the data in the cell appears after about half a second, not less, in general, very slowly. According to the button handler, if you execute the code, it also behaves.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace WindowsFormsApplication3 { public partial class Form1 : Form { private System.Data.OleDb.OleDbCommandBuilder cmdBuild; private System.Data.OleDb.OleDbDataAdapter da; private System.Data.OleDb.OleDbConnection conn; private System.Data.OleDb.OleDbCommand cmd; private System.Data.DataView dv; private System.Data.DataTable dt; private string connStr; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { try { connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=" + Application.StartupPath + @"\baza.mdb"; conn = new OleDbConnection(connStr); cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = "Select * from students"; dt = new DataTable(); da = new OleDbDataAdapter(cmd); conn.Open(); da.Fill(dt); conn.Close(); dv = new DataView(dt); dv.AllowDelete = false; dv.AllowEdit = true; dv.AllowNew = false; dataGridView1.DataSource = dv; } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button1_Click(object sender, EventArgs e) { try { cmdBuild = new OleDbCommandBuilder(da); da.UpdateCommand = cmdBuild.GetUpdateCommand(); conn.Open(); da.Update(dt); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { cmdBuild = new OleDbCommandBuilder(da); da.UpdateCommand = cmdBuild.GetUpdateCommand(); conn.Open(); da.Update(dt); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } 

    1 answer 1

    Found a solution, I hope the right one. Move the event to a separate thread. For example:

      private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { Task.Factory.StartNew(() => { try { cmdBuild = new OleDbCommandBuilder(da); da.UpdateCommand = cmdBuild.GetUpdateCommand(); conn.Open(); da.Update(dt); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }