Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy to clipboard all DataGridView cells issue

Posted on 2014-11-07
2
Medium Priority
?
148 Views
Last Modified: 2014-11-09
Hi all.

I'm facing another issue with the copy to clipboard functionality

I'm trying to use the below code to copy to clipboard but i get this message: 'SetDataObject' is not a member of 'System.Windows.Form.Button'

How can i fix this.

Thanks

    Private Sub clipboard_Click(sender As Object, e As EventArgs) Handles clipboard.Click
        DataGridView1.SelectAll()
        If DataGridView1.GetClipboardContent Is Nothing Then
            MessageBox.Show("Nothing selected to copy to clipboard.")
        Else
            Me.DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
            clipboard.SetDataObject(Me.DataGridView1.GetClipboardContent)
        End If
    End Sub

Open in new window

0
Comment
Question by:Wilder1626
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40431467
you have named your button clipboard which interferes with calling the "default" Clipboard.

Either rename your button or use full qualification for Clipboard:
System.Windows.Forms.Clipboard.SetDataObject(Me.DataGridView1.GetClipboardContent)

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 40431584
Thank you so much. This is perfect.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

824 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