如何触发telerikCommandCellClickEvent和其他按钮 [英] How can I fire telerikCommandCellClickEvent anonther button

查看:128
本文介绍了如何触发telerikCommandCellClickEvent和其他按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在winform上有一个telerik radgridview。它的名字是gridSigortaFirmalari。

我在commandcellclick上委托了一个事件。它使用gridSigortaFirmalari_CommandCellClick方法。我想从antoher按钮触发此方法。我尝试了这段代码,但我不知道这是真的方式和

我无法定义第3个参数,它是IInputEditor。



I have a telerik radgridview at my winform. It's name is gridSigortaFirmalari.
And I delegate an events on commandcellclick. It uses gridSigortaFirmalari_CommandCellClick method. I want to fire this method from antoher button. I tried this code but I don't know is it true way and
I can't define 3th parameter whic is IInputEditor.

foreach (GridViewRowInfo satir in gridSigortaFirmalari.Rows)
      {
       if (Convert.ToUInt32(satir.Cells["SirketID"].Value) == 8)
            {                               
         GridViewCellEventArgs eventt = new GridViewCellEventArgs(satir, gridSigortaFirmalari.Columns["SirketID"],???);
         gridSigortaFirmalari_CommandCellClick(satir, eventt);
        }
                                
   }

推荐答案

请参阅我对该问题的评论。



你搞乱了两件事:事件调用和方法调用。您有一个用于处理事件的方法,因此您可以随时调用它。 这已经解决了您的问题。



但是现在,这听起来是一个糟糕的UI设计理念。此外,您应该了解,您只能从类中声明一个事件,声明相应的事件成员,而不是其他任何地方,甚至不是派生类。因此,您无法直接在任何其他类型的方法中调用事件。这是.NET的一个重要的万无一失的功能。 (当然,声明类型可以暴露一些间接调用事件的方法。)



您可以更方便地处理事件,其中包括获得相同效果的可能性通过调用方法处理事件,如果使用匿名方法。例如,您实际上并没有使用事件参数参数,因此处理起来可以更容易:

Please see my comment to the question.

You are messing up two different things: event invocation and just a method call. You have a method used to handle the event, so you can always call it. This is already a solution to your "problem".

But now, it sounds a bad UI design idea. Also, you should understand that you can only invoke an event from the class declaring corresponding event member, nowhere else, not even from a derived class. So, you cannot invoke the event directly in the methods of any other types. This is an important fool-proof feature of .NET. (Of course, the declaring type can expose some methods invoking the event indirectly.)

You can handle events more conveniently, which includes the possibility to get the same effect as the event handling by calling a method, if you use anonymous methods. For example, you are not really using the event arguments parameters, so the handling can be easier:
this.gridSigortaFirmalari.CommandCellClick += (sender, eventArgs) =>
{
   HandleCommandCellClick(); // you can call this method elsewhere
}





-SA


这篇关于如何触发telerikCommandCellClickEvent和其他按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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