Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Components & Controls
Grids
Winforms Grids
call CellContentDoubleClick event from button outside DataGridView?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="jmcilhinney, post: 184909, member: 641"] You don't call an event. Events are raised when things happen. The [ICODE]CellContentDoubleClick[/ICODE] event is raised when the user double-clicks the contents of a cell. That's it, that's all. If you want the same code executed under two different sets of circumstances, i.e. when two different events are raised, then you have two choices: [LIST=1] [*]Add both events to the [ICODE]Handles[/ICODE] clause of the same method and put your code in that method. [*]Put your code in its own method and then call that method from two different event handlers. [/LIST] The first option is only available if the [ICODE]e[/ICODE] parameter is the same for both events of you don't use that parameter in the method and can declare it as the common [ICODE]EventArgs[/ICODE] type. It's also only an option if you want exactly the same code executed on both events. That means that it's not an option for you. What you need to do is write your own method that accepts either the grid row itself or its index as a parameter and then uses that row. You can then call that method from the two event handlers. I would suggest your new method should look like this: [CODE=vbnet]Private Sub EditRow(row As DataGridViewRow) Dim cell = row.Cells 'Etc' End Sub[/CODE] You would obviously copy the rest of the code you already have into there too. The event handler you currently have then becomes this: [CODE=vbnet]Private Sub DataGridView1_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick EditRow(DataGridView1.Rows(e.RowIndex)) End Sub[/CODE] and your new event handler would look like this: [CODE=vbnet]Private Sub BtnEdit_Click(sender As Object, e As EventArgs) Handles BtnEdit.Click EditRow(DataGridView1.CurrentRow) End Sub[/CODE] This is how you need to think when writing code: methods are chunks of functionality that can be invoked from wherever they are needed. [/QUOTE]
Insert quotes…
Verification
Post reply
Components & Controls
Grids
Winforms Grids
call CellContentDoubleClick event from button outside DataGridView?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom