单击刷新按钮在DataGridView中显示更新/添加/删除的记录. [英] Display updated/added/deleted record in DataGridView on Refresh Button Click.

查看:288
本文介绍了单击刷新按钮在DataGridView中显示更新/添加/删除的记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望在用户执行上述任何操作后,通过单击刷新按钮对数据库表(与该datagridview绑定)进行任何更改后,立即刷新datagridview(在屏幕上显示).

We want to refresh datagridview (displaying on screen) as soon as user makes any changes to the database table (binded with that datagridview) by clicking a Refresh button after any of above said operations.

How to do this?

推荐答案



请参考以下文章:如何插入,更新,删除使用DataGrid ..这篇文章介绍了如何执行所需的操作.

致谢,
Hi,

Please refer to the following post: How to insert, update, delete using DataGrid .. The post describes how to go about performing the actions you require.

Kind regards,


感谢您的答复,但实际上我的要求只是通过btnClick()事件刷新每个数据库表的更改上的DataGridView.
Thanks for your reply but actually my requirement is only to refresh DataGridView on each database table''s change through btnClick() event.


您需要做的是创建一个Refresh方法来更新您的数据源,然后重新绑定到DataGrid.
这是我将如何处理的概述

What you need to do is create a Refresh method that updates your Data Source and then rebinds to the DataGrid.
Here is an outline of how I would go about it

public partial class MainWindow : Window
    {
        private List<yourItems> listItems;
        public MainWindow()
        {
            InitializeComponent();
            listItems = new List<yourItems>();
            Refresh();
        }
        private void Refresh()
        {
            listItems = DataAccess.GetData();
            DataGridView1.DataSource = listItems;
        }
        private void button1_click(object sender, EventArgs e)
        {
            Refresh();
        }
}



希望对您有帮助



Hope this helps


这篇关于单击刷新按钮在DataGridView中显示更新/添加/删除的记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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