如何在按钮单击事件中调用GridView_CellClick()事件? [英] How to call GridView_CellClick() event in button click event?
本文介绍了如何在按钮单击事件中调用GridView_CellClick()事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在另一个按钮点击事件中调用GridView_CellClick()。
Hi All,
I want to call GridView_CellClick() in another button click event.
Private Sub ContextGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ContextGridView.CellClick
End Sub
我不知道在按钮点击事件中调用它时如何将参数传递给GridView_CellClick()。
我尝试时遇到以下异常。
I dont know how to pass the arguments to GridView_CellClick() when calling it in button click event.
I got the following exception when I tried.
Public Sub bt_CreateName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_CreateName.Click
ContextGridView_CellClick(sender, e)
End sub
无法转换类型为'的对象'System.EventArgs''键入''System.Windows.Forms.DataGridViewCellEventArgs''。
请帮助。
提前致谢!
Unable to cast object of type ''System.EventArgs'' to type ''System.Windows.Forms.DataGridViewCellEventArgs''.
Please Help.
Thanks in advance!
推荐答案
不要这样做!
如果代码的某些部分应该在两个事件中都有效:Button_Click
事件和DataGridView_CellClick
,移动它进入另一个函数/程序。
Don''t do that!
If some part of code should work in both events:Button_Click
event andDataGridView_CellClick
, move it into another function/procedure.
Private Sub DoSomething(CurrentDGVCell As Integer)
'here your code
End Sub
然后这样打电话:
then call like this:
Private Sub ContextGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ContextGridView.CellClick
DoSomething(GetCurrentDGVCell)
End Sub
Public Sub bt_CreateName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_CreateName.Click
DoSomething(GetCurrentDGVCell)
End sub
这篇关于如何在按钮单击事件中调用GridView_CellClick()事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文