if语句中如何单击按钮 [英] how to check button is clicked inside if statement

查看:171
本文介绍了if语句中如何单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个Windows窗体,我需要的是,如果我们单击datagriedview中的任何ROW,然后单击该窗体中的Delete按钮,它应该打开另一个窗体.
为此,我创建了一个ROW_click事件方法,该方法很好,但同时我想检查是否在此方法内单击了删除按钮.

请帮帮我.

Hi all,

I''ve a windows Form and what I need is if we click on any ROW in datagriedview and click on delete button in the form, it should have another form open.
For this, I created a ROW_click Event Method, that''s fine, but simultaneously I want to check if the delete button is clicked inside this method.

please help me out.

private void dgvRow_Click_delet(object sender, EventArgs e)
       {
           if (btnDelete.c)//my question is on this.
           {
               AdrsdetailShow();
           }

         }


将OP添加为答案:

对不起,我很困惑.
在这里,我确切地告诉您需要做什么,我们应该选择任何行,如果我们单击Delete按钮,它将显示另一种形式.
如何实现?"

然后添加为另一个答案:

感谢您的答复.请告诉我如何计算selectedRows或如何通过示例使用SelectedRows属性.帮帮我"


[edit] OP答案移至问题-OriginalGriff [/edit]


The OP added as an answer:

"Sorry, I am confused.
Here I tell you exactly what needs to be, we should select any row and if we click delete button it''ll show another form.
How would it be achieved?"

And then added as another answer:

"thank u for reply. please tell me how to count selectedRows or to use SelectedRows property with an example. help me out"


[edit]OP answers moved to question - OriginalGriff[/edit]

推荐答案

不,抱歉,它不能那样工作.

当用户单击DataGridView中的任何行时,他无法同时单击表单中的删除按钮:他只有一个鼠标指针!

您实际上想实现什么,因为我认为您的实现有些混乱!


对不起,我很困惑.在这里,我告诉你确切是什么,我们应该选择任何行,如果单击删除按钮,它将显示另一种形式.它将如何实现.回复我"

请不要使用添加答案"按钮-如果您使用添加评论",那么我会收到一封电子邮件,而不是在将来的某个时候回头.通常,您会以这种方式获得更快的响应!

正如Espen Harlinn所说,DGV具有一个SelectedRows属性,您可以在Button单击事件中对其进行迭代:
No, sorry it doesn''t work like that.

When the user clicks on any row in the DataGridView, he can''t simultaneously click on a delete button in your form: he only has one mouse pointer!

What are you actually trying to achieve, because I think your implemenation is getting a little confused!


"sorry, i confused. here i tell u exactly what needs to be, we should select any row and if we click delete button it''ll show another form. how would it achieved. reply me"

Please do not use the "Add answer" button - if you use "Add Comment" then I get an email, rather than my looking back at some point in the future. You generally get a quicker response that way!

As Espen Harlinn says, The DGV has a SelectedRows property which you can iterate through in your Button click event:
foreach (DataGridViewRow row in myGrid.SelectedRows)
   {
   ...
   }

然后,您可以组装所需的任何信息并显示第二种形式.

You can then assemble whatever information you want and show your second form.


就像OriginalGriff所说的那样,您的设计似乎有些不合常规. DataGridView具有SelectedRows属性,使您可以确定选择了哪些行.还有一个SelectionMode属性,使您可以决定选择如何用于DataGridView.

我认为您应该使用此机制来确定按钮单击事件处理程序中的选定行.然后,您可以显示其他表格.

问候
Espen Harlinn
As OriginalGriff said your design seems a bit unorthodox. The DataGridView has a SelectedRows property allowing you to determine which rows are selected. There is also the SelectionMode property that allows you to decide how selection works for your DataGridView.

I think you should use this mechanism to determine the selected rows in your button click event handler. You can then show you other form.

Regards
Espen Harlinn


这篇关于if语句中如何单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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