title: Capturing the ctrl+V in VB.NET combobox
body: <p>I am trying to remove the newline and replace with whitespace before pasting to comboBox as it ignores anything beyond a line. I am trying this:</p>
  
  <pre><code>If e.Modifiers = Keys.Control AndAlso e.KeyValue = Keys.V Then Then
              Clipboard.SetText(Regex.Replace(Clipboard.GetText(TextDataFormat.UnicodeText), "\n", " "))
              e.Handled = True
          End If
  </code></pre>
  
  <p>I am performing this inside KeyDown event but it is able to capture either Ctrl or V but not both. I tried <a href="https://stackoverflow.com/questions/15958250/capture-ctrlv-or-paste-in-a-textbox-in-net">Capture CTRL+V or paste in a textbox in .NET</a> and <a href="http://social.msdn.microsoft.com/Forums/windows/en-US/096540f4-4ad4-4d24-ae12-cfb3e1b246f3/interceptingoverriding-paste-behavior-on-combobox" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/windows/en-US/096540f4-4ad4-4d24-ae12-cfb3e1b246f3/interceptingoverriding-paste-behavior-on-combobox</a> but no results as desired. May be there is something i am missing in my code. Please help me out.</p>
  
  <p>I am getting the needed value with this Clipboard.GetText().Replace(vbCrLf, " ") when i debug but i am not able to set it. I tried using a variable to set it but even then no change. I also tried clearing the clipboard and then resetting with this variable holding the modified value. </p>
  
  <p>I am using Winforms and i tried this but still no change to my clipboard:</p>
  
  <pre><code>Private Const WM_PASTE As Integer = &amp;H302
      Protected Overrides Sub WndProc(ByRef m As Message)
          If m.Msg = WM_PASTE Then
              Dim returnText As String = Nothing
              If (Clipboard.ContainsText()) Then
                  returnText = Clipboard.GetText().Replace(vbCrLf, " ")
                  Clipboard.Clear()
                  Clipboard.SetText(returnText)
              End If
          End If
          MyBase.WndProc(m)
      End Sub
  </code></pre>