问题从另一个表单刷新dataGridView [英] problem refresh a dataGridView from another form

查看:47
本文介绍了问题从另一个表单刷新dataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨那里


编辑后我遇到问题,编辑后不刷新数据网格。

使用系统; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;

名称空间Sqlite_Entity_2017_OK
{

公共部分类Frm_Edit:表格
{
DBEntiti db = new DBEntiti();
public Frm_Edit(Frm_Main fm)
{
InitializeComponent();
fmm = fm;
}



public int ID_Dg;
private void Frm_Edit_Load(object sender,EventArgs e)
{

}


// ******** **********
public delegate void UpdateDelegate(object sender,UpdateEventArgs args);
公共事件UpdateDelegate UpdateEventHandler;
Frm_Main fmm;
公共类UpdateEventArgs:EventArgs
{
public string Data {get;组; }
}


protected void GetList()
{
UpdateEventArgs args = new UpdateEventArgs();
UpdateEventHandler?.Invoke(this,args);
}

private void btnEdit_Click(object sender,EventArgs e)
{

Tbl_List Tbl = db.Tbl_List.First(i => i .ID == ID_Dg);
Tbl.Name = txtName.Text;
Tbl.Family = txtFamily.Text;

db.SaveChanges();
GetList();
MessageBox.Show(" done edit"," box");

}
// *******************



}

解决方案

< blockquote>

确实没有足够的信息代码来提供理由。


我要说的是DataGridView无法刷新。仍然有限的细节我会更新数据库,如果成功通过设置应在DataGridView中可视反映的相应属性更新有问题的行。对于
示例,在
以下代码示例
中,我获得了当前在DataGridView中的行并编辑子窗体中的行然后重置DataGridView中的当前行。现在这是在Entity Framework / DataGridView中,当使用SqlClient或OleDb数据
提供者时,这个想法是一样的。 


如果你在DataGridView中使用DataSet直接编辑或DataTable为它的DataSource,你可以订阅DataTable事件来获取更改,将它们保存回数据库,而无需刷新DataGridiView。


所以你永远不必使用DataGridView来刷新实体框架或托管数据提供商,如果逐个保存记录。 


如果使用TableAdapters,他们会为您处理此事。


结束时我无法提供直接答案,因为您的详细信息是广泛的。


hi there

i have problem after edit , don't refreshing data grid after edit.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sqlite_Entity_2017_OK
{

    public partial class Frm_Edit : Form
    {
        DBEntiti db = new DBEntiti();
        public Frm_Edit(Frm_Main fm)
        {
            InitializeComponent();
            fmm = fm;
        }



        public int ID_Dg;
        private void Frm_Edit_Load(object sender, EventArgs e)
        {

        }


        //******************
        public delegate void UpdateDelegate(object sender, UpdateEventArgs args);
        public event UpdateDelegate UpdateEventHandler;
        Frm_Main fmm;
        public class UpdateEventArgs : EventArgs
        {
            public string Data { get; set; }
        }


        protected void GetList()
        {
            UpdateEventArgs args = new UpdateEventArgs();
            UpdateEventHandler?.Invoke(this, args);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {

            Tbl_List Tbl = db.Tbl_List.First(i => i.ID == ID_Dg);
            Tbl.Name = txtName.Text;
            Tbl.Family = txtFamily.Text;

            db.SaveChanges();
            GetList();
            MessageBox.Show("done edit", "box");

        }
        //*******************



    }

解决方案

There is truly not enough information code wise to provide a reason.

What I will say is a DataGridView has no capabilities to refresh. Still with limited details I would update the database, if successful update the row in question by setting the appropriate properties which should reflect visually in the DataGridView. For example, in the following code sample I get the current row in the DataGridView and edit the row in a child form then reset the current row in the DataGridView. Now this is in Entity Framework/DataGridView yet the idea is the same when using SqlClient or OleDb data providers. 

If you are editing directly in the DataGridView with a DataSet or DataTable for it's DataSource you can subscribe to DataTable events to get changes, save them back to the database without any need to refresh the DataGridiView.

So you should never have to refresh a DataGridView using Entity Framework or a managed data provider if saving records one by one. 

If using TableAdapters they handle this for you.

In closing I can't provide a direct answer as your details are way to broad.


这篇关于问题从另一个表单刷新dataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆