Solved

Copying DataGridView Cells to an Excel spreadsheet using Control-C

Posted on 2013-12-09
4
527 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

627 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