Allowing Control C from Datagridview in VB.net

For some reason a couple a datagridviews in my vb.net application won't allow me to select rows, select individual cells, or select the whole datagridview and copy it to the clipboard.  I want to be able to copy the whole DGV over to an excel sheet or select a single cell and copy then paste it to Google for instance.  I'd like to use control c and control v like a normal application.

Any way to allow this without a lot of code?  Am I missing a setting somewhere?

Clipboardcopymode: EnableWithoutHeaderText
Adding, Deleting, Editing, Reordering is all enabled.
DGV is unbound and is filled programmatically from a database.
zipnoticAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
I think you should add a Copy2Clip method similar to the  click event ...  http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.clipboardcopymode.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2  or http://www.codeproject.com/Tips/491462/Copying-DataGridView-Contents-To-Clipboard

                ' Add the selection to the clipboard.
                Clipboard.SetDataObject( _
                    Me.DataGridView1.GetClipboardContent())

Open in new window


then add an event handler for the DGV to trap keypress, specifically Ctl-C.  On this keypress, call the Copy2Clip function.
zipnoticAuthor Commented:
Private Sub dgPgs_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles dgPgs.KeyPress
       
        Debug.Print(AscW(e.KeyChar))
    End Sub

Perhaps there is something more sinister occurring.  This code produces the expected values for regular keys and for MOST ctl-? values.  When I try ctrl-C or ctrl-V the keypress event does not fire at all.  ctrl-A works fine and several other ctrl combinations...

If I read correctly, CTL-C should result in an ascii code of 3?


Any ideas?

Control-C works for every other application.
Robberbaron (robr)Commented:
i suspect that the control is trapping Ctlc-C first, but not letting you act on it.

try turning Clipboardcopymode: Disable
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

zipnoticAuthor Commented:
Tried Clipboardcopymode: Disable

No Luck.

I found that CTRL-Z, X, C, V does not register with the control.  All other CTRL - ?  values seem to work just fine.  

I also tried turning the forms KeyPreview: True and that also did not help.

Other Ideas?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zipnoticAuthor Commented:
I had to use the KeyUp event and look for the combination of control&C, then deal with clipboard.  Works a treat. Thanks much.

        If e.Control And e.KeyValue = 67 Then
            dgs.ClipboardCopyMode =DataGridViewClipboardCopyMode.EnableWithoutHeaderText
            Clipboard.Clear()
            Clipboard.SetDataObject(Me.dgs.GetClipboardContent())
            Debug.Print("Control-C pressed")
        End If
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.