Solved

VB.net DataGridView double click

Posted on 2014-04-23
2
2,103 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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