|
-
Jul 9th, 2007, 10:18 AM
#1
Thread Starter
Hyperactive Member
[2005] Paste from clipboard.
I am trying to paste negative values copied from Excel formatted with the (123) into a DataGrid. When I copy it with the column formatted to a decimal it rejects the value because it reads it as a string "(123)" instead of "-123". Is it possible to catch the text from the clipboard and replace the ( with a - and then get rid of the second ) ..
Last edited by NPassero; Jul 9th, 2007 at 10:36 AM.
-
Jul 9th, 2007, 11:15 AM
#2
Thread Starter
Hyperactive Member
Re: [2005] Paste from clipboard.
I can do it using a button just calling this sub routine. But i need to capture the paste event, anyone know how to pull that off.
vb.net Code:
Private Sub PasteRoutine()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()
Dim myString As String = objClipboard.GetData(DataFormats.Text).ToString
Dim first As Integer = myString.IndexOf("(")
Dim second As Integer = myString.IndexOf(")")
If first > -1 And second > -1 Then
If IsNumeric(myString.Substring(first, (myString.Length - second) + second)) Then
myString = myString.Replace("(", "-")
myString = myString.Replace(")", "")
formulaTB.Text = myString
End If
End If
End Sub
-
Jul 9th, 2007, 06:18 PM
#3
Re: [2005] Paste from clipboard.
There is no event specifically associated with data being pasted. I'm guessing that there's a Windows message associated with a paste action so you could inherit the control, override the WndProc method and test to find what message(s) that might be. Once you know that you can trap that message and take the appropriate action.
-
Jul 9th, 2007, 06:35 PM
#4
Re: [2005] Paste from clipboard.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 9th, 2007, 09:21 PM
#5
Re: [2005] Paste from clipboard.
I just did a quick test with a TextBox and the TextChanged event was raised before the WM_PASTE message was received, so that would mean that the value would already have been rejected before you became aware that a paste operation was taking place.
What you could do is instead of using Ctrl+V, select a different key combination (e.g. Ctrl+Alt+V) and trap it in the KeyDown event of the target control. You can then call your PasteRoutine method to process the value that is currently on the clipboard.
-
Jul 10th, 2007, 10:05 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] Paste from clipboard.
Alright, I changed the code a little but, this could work perfectly if there was a way to check if the clipboard data has changed. Any event handler to do that ?
-
Jul 11th, 2007, 08:39 AM
#7
Member
Re: [2005] Paste from clipboard.
Hello Guys... (In the same vein)
I am doing a Clipboard.SetDataObject(WorkSheetObj.Range("A6:A9").Copy().ToString)
and am going to OUTLOOK
and do a control V
What's being pasted is "TRUE"
not the contents of those cells in Excel..
Any ideas how to do this right?
Thanks in advance
-
Jul 12th, 2007, 02:27 PM
#8
Re: [2005] Paste from clipboard.
Looks like you are not using the proper type of the expected data.
Clipboard.SetText(WorkSheetObj.Range("A6:A9"))
Or such
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|