如果数组具有除其内容之外的数据,则触发事件 [英] Trigger an event if array has data other than its contents

查看:62
本文介绍了如果数组具有除其内容之外的数据,则触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想知道当我得到的值与数组&相比时如何触发事件如果值不在该数组内,则只触发事件。



就像我有一个datagridview&我正在使用它的单元格点击事件。如果单击单击等于某个索引,则会发生一个事件,如果该单元格单击值不是数组的内容,则只有事件必须触发。如何处理这种情况?



datagridview单元格点击事件的代码如下:



Hi all,

I wanted to know how to trigger an event when the value i get is compared with an array & if the value is not within that array only then trigger an event.

Like i have a datagridview & i am using cell click event of it. If cell click is equal to some index then one event occurs, if that cell click value is other than the contents of the array only then an event has to trigger. How to approach this type of condition?

The code for datagridview cell click event is given below:

private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
       {

if (BSView1.Rows[0].Cells[0].Value != null)
           {
               if (e.RowIndex >= 0)
               {
                   for (int i = 0; i < fieldindex1.Count; i++)
                   {
                   if (Convert.ToInt16(fieldindex1[i]) == dgv1.CurrentCell.RowIndex)
                       {
                           HeaterTimer.Start();                           
                       }
                   else if(Convert.ToInt16(fieldindex1[i]) != dgv1.CurrentCell.RowIndex)
                       {
                           HeaterTimer.Stop();
                       }
                  }
               }
           }





这里如果在fieldindex数组中有2像fieldindex1 = {2,5}&如果条件满足,则dgv1.CurrentCell.RowIndex为0 1st&在第二次迭代期间它变得虚假&计时器停止。我希望它仅在dgv1.CurrentCell.RowIndex值不是fieldindex数组时停止。此外,fieldindex数组仅填充值&没有零。它是一个动态数组,其大小随着添加的值而增加。



Here if in fieldindex array has 2 values like fieldindex1={2,5} & if dgv1.CurrentCell.RowIndex is 0 1st if condition will be satisfied & during the 2nd iteration it becomes false & the timer stops. I want it to stop only if the dgv1.CurrentCell.RowIndex value is other than the fieldindex array. Also the fieldindex array is filled with only values & no zeros are present. Its a dynamic array its size increases with the value that is added to it.

推荐答案

这称为调用事件。事情就是这样:除了声明这个偶数的类型之外,不可能在任何地方调用事件。您甚至无法在派生类中执行此操作。这是一个良好的万无一失的功能,旨在保护您免受误解。在宣布课程之外调用一个事件将是一件坏事;你永远不需要它。相反,你只需要具有与调用事件时相同的效果,对吧?然后执行以下操作:创建一些方法并从事件处理程序调用。这样,您可以在其他地方调用相同的方法。



请参阅我过去的答案: UserControl自定义事件 [ ^ ]。



-SA
This is called "invoke an event". Here is the thing: it is impossible to invoke an event anywhere except the type where this even was declared. You cannot even do it in a derived class. This is a good fool-proof feature which is designed to protect you from your misconception. Invocation of an event outside its declaring class would be a bad thing; you never need it. Instead, you just need to have the same effect as when the event is invoke, right? Then do exactly this: create some method and call if from an event handler. This way, you can call the same method elsewhere.

Please see also my past answer: UserControl custom event[^].

—SA


这篇关于如果数组具有除其内容之外的数据,则触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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