Solved

Copying DataGridView Cells to an Excel spreadsheet using Control-C

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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