Solved

VB.net DataGridView double click

Posted on 2014-04-23
2
2,149 Views
Last Modified: 2014-04-27
Hi
I have an Excel add-in where I am trying to get information from a DataGridView onto
a spreadsheet with the code below. The problem is that it doesn't work every time I double click. Is there a better way to do this


    Private Sub DataGridView1_CellDoubleClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        Try
            Dim oRowIndex As Integer = e.RowIndex
            Dim oColumnIndex As Integer = e.ColumnIndex
            Dim oDescription As String = Me.DataGridView1.Rows(oRowIndex).Cells(1).Value
            Dim oPrice As String = Me.DataGridView1.Rows(oRowIndex).Cells(2).Value
            Dim oPriceExVAT As String = Me.DataGridView1.Rows(oRowIndex).Cells(3).Value

            Dim oActiveCellRow As Long = Globals.ThisAddIn.Application.ActiveCell.Row
            Globals.ThisAddIn.Application.Cells(oActiveCellRow, 1).value = oDescription
            Globals.ThisAddIn.Application.Cells(oActiveCellRow, 2).value = oPrice
            Globals.ThisAddIn.Application.Cells(oActiveCellRow, 3).value = oPriceExVAT

        Catch ex As Exception
            MsgBox(ex.Message & " 8bb")
        End Try
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 18

Accepted Solution

by:
dj_alik earned 500 total points
ID: 40019341
Try the CellMouseDoubleClick event...

Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
    If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
        Dim selectedRow = DataGridView1.Rows(e.RowIndex)
    End If
End Sub
0
 

Author Closing Comment

by:murbro
ID: 40026646
Thanks very much
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question