更新的GridView的一种形式 [英] Updating the gridview in one form

查看:141
本文介绍了更新的GridView的一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,的DataGridView

予有两种形式,在一种形式中的数据将被填充由在DataGridView

I have two forms, in one form the data will be populated by the DataGridView.

当我们点击gridview的另一种形式将打开,相应的列值的列标题。

When we click on the column header of the gridview the other form will be opened with the corresponding column values.

我已经做了在窗口2中的数据的一些操作,以便关闭窗口2之前,我想更新Form1的gridview的这些细节...

I have done some manipulations on the data in form2 so before closing form2 I want to update the form1 gridview with these details...

我已经见过像事件处理程序附着在Form1的一些细节,但我没有找到一个确切的答案。

I have seen some details like eventhandler attachment in form1, but I didn't find an exact answer.

推荐答案

表格2 code

    public event EventHandler<UpdatedEventArgs> updateEvent;

    public class UpdatedEventArgs : EventArgs
    {
        public string SomeVal { get; set; } // create custom event arg for your need
    }

    protected virtual void OnFirstUpdateEvent(UpdatedEventArgs e)
    {
        if (updateEvent != null)
            updateEvent(this, e);
    }


    private void button1_Click(object sender, EventArgs e)
    {
        UpdatedEventArgs eventData = new UpdatedEventArgs(); 
        eventData.SomeVal = "test"; // set update event arguments, according to your need

        OnFirstUpdateEvent(eventData);
    }

    public Form2()
    {
        InitializeComponent();
    }

表格1 code

    public Form1()
    {
        InitializeComponent();

        Form2 form2 = new Form2();
        form2.updateEvent += new EventHandler<Form2.UpdatedEventArgs>(form2_updateEvent); // create event handler to update form 1 from form 2
        form2.Show();
    }

    void form2_updateEvent(object sender, Form2.UpdatedEventArgs e)
    {
        if (e != null && e.SomeVal != null)
        {
            // Do the update on Form 1 
            // depend on your event arguments update the grid  
            //MessageBox.Show(e.SomeVal); 
        }

    }

这篇关于更新的GridView的一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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