将一个类的事件调用到另一类的网格事件 [英] invoking the event of one class to another class of grid event

查看:79
本文介绍了将一个类的事件调用到另一类的网格事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class class1
{
public void RefreshParameter()
        {
            gcUnitPRMS.ProcessGridKey += new KeyEventHandler(gcUnitPRMS_ProcessGridKey);

           // gcUnitPRMS.ProcessGridKey += new KeyEventHandler(gcUnitPRMS_ProcessGridKey);
        }

        public void gcUnitPRMS_ProcessGridKey(object sender, KeyEventArgs e)
        {
            GridControl grid = (GridControl)sender;
            GridView view = (GridView)grid.FocusedView;

            if (view.Name != "gvUnitPRMs")
                return;

            DataRowView master = (DataRowView)view.SourceRow;
            if (Convert.ToString(master["TypeCategory"]) == Categories.sUnitParameters)
                return;

            if (e.KeyCode == Keys.Enter)
            {
                if (!view.IsEditing)
                {

                    if (view.UpdateCurrentRow())
                    {

                        AddNewPRMRow(view);
                    }
                }
            }
            else if (e.KeyCode == Keys.Delete)
            {
                if (!view.IsEditing)
                {
                    DialogResult res = XtraMessageBox.Show("Are You Sure To Delete", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (res == DialogResult.Yes)
                    {

                        DeletePRMRow(view);
                    }
                }
            }
            AddNewPRMRow(view);
            int rhandle = view.FocusedRowHandle;
            GridColumn gcol = view.Columns["unit_param_desc"];
            view.SetFocusedRowCellValue(gcol, description1);
           
        }
}
class class2
{
class1 cs=new class1();
private void treeList1_AfterFocusNode(object sender, NodeEventArgs e)
    {
        TreeList tr1 = sender as TreeList;
        if (e.Node.ParentNode != null)
        {
            parameter.description = e.Node.GetValue("OPCName").ToString();
            if (e.Node.ParentNode.ParentNode != null)
            {
 cs.servername1 = e.Node.ParentNode.ParentNode.GetValue("OPCName").ToString();
    cs.host1 = e.Node.ParentNode.ParentNode.GetValue("OPCIPAddress").ToString();
                cs.RefreshParameter();
            }

        }      

    }

}


我已经在该函数的另一个类中调用了class1函数,但是该函数将调用网格事件,但是当我调用它时,它将不会调用该事件.
为什么会这样.
在此先感谢.


[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]


I have invoked the class1 function in another class in this function invoke the event of the grid but when i have call this it will not invoked the event.
why this happens.
thanks in advance.


[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]

推荐答案

据我所知,您的意思是调用RefreshParameter方法从class2通过实例化,

如果触发了treeList1_AfterFocusNode事件,并且如果命中了"cs.RefreshParameter();"行的断点,那么将调用您的方法,请确保是否满足前几行的条件.
还有一件事,您只是在RefreshParameter中挂了一个事件,如果您希望发生这种情况,则不必调用gcUnitPRMS_ProcessGridKey事件!您可能需要看一下事件处理.

希望这会有所帮助.
To my understanding, you mean to call the RefreshParameter method from class2 by instantiating,

There is no magic, if treeList1_AfterFocusNode event is fired and if a breakpoint at the line '' cs.RefreshParameter();'' is hit your method will be invoked, ensure if the conditions in the previous lines are satisfied.

One more thing, you just have hooked an event in the RefreshParameter, this does not necessarily call the gcUnitPRMS_ProcessGridKey event, if you expect this to happen,! you may have to take a look at event handling.

Hope this helps.


这篇关于将一个类的事件调用到另一类的网格事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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