如何使用代理处理网格绑定 [英] How Can I Handle Grid Bind Using Delegates

查看:81
本文介绍了如何使用代理处理网格绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口表单,当我点击添加按钮时,当我点击此表单的确定按钮(secode表单)新表单打开时再次打开一个新表单并单击此表单按钮的保存按钮主网格刷新表单,主网格刷新保存和取消按钮,但我想只刷新保存按钮上的网格而不是取消使用委托,我该怎么办,请帮助我。

i have a window form, when i click on add button a new form open again when i click on ok button of this form(secode form) new form open and click the save button of this form button a grid refresh of main form , the main grid refresh on save and also cancel button , but i want to only refresh grid on save button not on cancel using delegate , how can i do this please help me.

推荐答案

不要使用委托 - 使用事件:你有三种形式:

main - >第二个 - >第三个

当您按下第三个表单中的按钮时,它表示以第二个表单处理的事件。

此事件处理程序引发一个事件,由主表单处理,然后刷新它自己的网格。



安排非常简单:一个简单的代码片段来添加事件 [ ^ ]向您展示如何(以及向Visual添加一个片段)工作室让以后更容易)

在两个表格之间传递信息,第2部分:儿童到父母 [ ^ ]显示示例o f使用事件做类似的事情。
Don't use delegates - use events: you have three forms:
main -> second ->third
When you press the button in the third form, it signals an event which is handled in the second form.
This event handler raises an event which is handled by the main form which then refreshes it's own grid.

This is very simple to arrange: A Simple Code Snippet to Add an Event[^] shows you how (as well as adding a snippet to Visual Studio to make it easier later)
And Transferring information between two forms, Part 2: Child to Parent[^] shows an example of using events to do something similar.


是的,你可以使用代理。

在我看来,活动也是代表。请参阅下面的代码,它与您的答案无关,但您肯定会知道它是如何工作的。



Yeah, you can use delegates.
In my opinion events are delegates too. See my code below, it is not relevant to your answer, but you will certainly have an idea how it works

Form_Load(...)
{
    addBtn.Click += delegate
    {
        // do your operations
    };
}





如果您有任何疑问,请告诉我:)



-KR



Let me know, if anything is not clear to you :)

-KR


这篇关于如何使用代理处理网格绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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