简体   繁体   English

从未调用过DataGridViewButtonColumn处理程序

[英]DataGridViewButtonColumn Handler Never Called

I am creating a simple Windows Form with a DataGridView that contains a total of 6 columns. 我正在使用一个包含总共6列的DataGridView创建一个简单的Windows窗体。 Only one of these columns (the very first) is a button column. 这些列(仅第一列)中只有一个是按钮列。 I am having trouble with the handler for when the button, or rather, cell is clicked. 我在单击按钮或确切地说单击单元格时遇到处理程序问题。

For reference (if it matters), the name of my DataGridView is infoGrid . 作为参考(如果有关系),我的DataGridView的名称为infoGrid

The only operation that I have the handler perform is a simple popup window, just so I can know the handler is being correctly called. 我让处理程序执行的唯一操作是一个简单的弹出窗口,以使我知道正确调用了处理程序。 I also have not added conditions yet to ensure it was the first column that was clicked, but I do plan on implementing conditions when I can get the handler to properly work. 我还没有添加条件来确保它是被单击的第一列,但是当可以使处理程序正常工作时,我确实计划实现条件。 This is what I have: 这就是我所拥有的:

    private void infoGrid_CellClick(object sender, DataGridViewCellEventArgs e)
    {
         MessageBox.Show("It's working.", "Test", MessageBoxButtons.OK);
    }

After spending a couple of hours scouring the internet for an answer, I noticed that just about all examples on this website and others use dataGridView1_CellClick for their method name. 花了几个小时在互联网上寻找答案之后,我注意到该网站上的几乎所有示例以及其他示例都使用dataGridView1_CellClick作为方法名称。 I wasn't sure if that was just a generic answer, but I tried it myself, and still got nothing. 我不确定这是否只是一个通用答案,但我自己尝试了一下,却一无所获。

I added breakpoints at the beginning of this method as well, and found that no matter how many times I click ANY cell, the handler is never even called. 我也在该方法的开头添加了断点,并且发现无论我单击ANY单元多少次,该处理程序甚至都不会被调用。

Does anybody know what I may be doing wrong? 有人知道我可能做错了吗? All help is appreciated! 感谢所有帮助!

CDove actually answered this for me in his comment to the original question, but I just wanted to make it more visible for anyone else who may have the same problem. CDove在对原始问题的评论中实际上为我回答了这个问题,但是我只是想让其他可能遇到相同问题的人更清楚地看到它。

After creating the handler method, you have to go to the designer and click the lightning bolt "Events" button under the "Properties" side bar. 创建处理程序方法后,必须转到设计器并单击“属性”侧栏下的闪电“事件”按钮。 Then find the event you want to handle, and add the handling method that you created to it. 然后找到您要处理的事件,并向其添加您创建的处理方法。

Once again, credit for this answer goes to CDove. 再一次,这个答案归功于CDove。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM