Solved

Copying DataGridView Cells to an Excel spreadsheet using Control-C

Posted on 2013-12-09
4
523 Views
Last Modified: 2013-12-15
I have a VB.Net app that contains a DataGridView. I need to incorporate functionality that allows the User to click in a specific cell and then drag the cursor from that cell to wherever they wish within the grid, selecting each cell within the range of the two points as it is being dragged. Once all the desired cells are selected, User can press "CTRL-C" to copy the data to an Excel Spreadsheet.
0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39708226
What have you tried, and what can I help you with?
0
 

Author Comment

by:BlakeMcKenna
ID: 39708638
Well, after looking at the situation a little further, I tried a test by dropping a new DGV onto a form and populating it with rows and columns. I tried to drag and move the cursor over the rows/columns and it worked just like in Excel. So, there is obviously something wrong with the way I have configured my dgv...just not sure what it would be. Do you know of any settings that would prevent it from allowing the dragging and selecting of cells? Here are the events below that I am currently using within my app.

        Private Sub dgvLoadTests_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles dgvLoadTests.CellValidating
        Try
            EH.strRetVal = ""

            If dgvLoadTests.Item(e.ColumnIndex, e.RowIndex).IsInEditMode Then
                If Not dgvLoadTests.Item(e.ColumnIndex, e.RowIndex).ValueType Is GetType(Decimal) Then
                    Dim c As Control = dgvLoadTests.EditingControl
                    Dim cell As DataGridViewCell = dgvLoadTests.CurrentCell

                    If Not Decimal.TryParse(c.Text, Nothing) Then
                        If c.Text = "" Then
                        Else
                            EH.strRetVal = "Invalid Numeric Value!" & "~I"
                            e.Cancel = True
                        End If
                    Else
                        cell.Value = Format(c.Text, GetDecimalPlaces(c.Text))
                    End If
                    dgvLoadTests.CancelEdit()
                End If
            End If

        Catch ex As Exception
            EH.strRetVal = gfrmID & "/dgvLoadTests_CellValidating() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.strRetVal)
    End Sub

    Private Sub dgvLoadTests_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvLoadTests.KeyDown
        Try
            EH.strRetVal = ""

            'Delete the value in the current cell
            If e.KeyCode = Keys.Delete Then
                Dim cell As DataGridViewCell = dgvLoadTests.CurrentCell
                cell.Value = ""
            End If

        Catch ex As Exception
            EH.strRetVal = gfrmID & "/dgvLoadTests_KeyDown() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.strRetVal)
    End Sub
0
 

Accepted Solution

by:
BlakeMcKenna earned 0 total points
ID: 39708648
I just now figured it out. I had the "MultiSelect" property set to "False". I set it back to "True" and it worked like I wanted it to.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39719712
I figured it out.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 86
RLDC Reporting in Visual studio 11 43
vb.net sendkey 4 18
Create simple VB.net Add-in for Excel in Office 365 2 20
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

749 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