Solved

Copying DataGridView Cells to an Excel spreadsheet using Control-C

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now