Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to call GridView_CellClick() in another button click event.

VB
Private Sub ContextGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ContextGridView.CellClick

End Sub


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.

VB
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


Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.DataGridViewCellEventArgs'.

Please Help.

Thanks in advance!
Posted
Updated 11-Apr-13 3:39am
v2

1 solution

Don't do that!

If some part of code should work in both events: Button_Click event and DataGridView_CellClick, move it into another function/procedure.

VB
Private Sub DoSomething(CurrentDGVCell As Integer)
'here your code
End Sub

then call like this:
VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900