Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27036

[RESOLVED] Unable to cast from toolstrip container to textbox error

$
0
0
hey all, i have made a form for some calculation purpose.
i have a menustrip & a toolstrip jn which i have cut copy & paste buttons.
the menustrip & toolstrip are in a toolstrip container.
i am using the following code for copy button but its showing an error UNABLE TO CAST FROM TOOLSTRIPCONTAINER TO WINDOWS.FORMS.TEXTBOX
Code:

Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
        Clipboard.SetDataObject(CType(ActiveControl, TextBox).SelectedText)
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
            Clipboard.SetDataObject(CType(ActiveControl, TextBox).SelectedText)
        CType(ActiveControl, TextBox).SelectedText = ""

    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
            Dim oDataObject As IDataObject
        oDataObject = Clipboard.GetDataObject()
        If oDataObject.GetDataPresent(DataFormats.Text) Then
            CType(ActiveControl, TextBox).SelectedText = CType(oDataObject.GetData(DataFormats.Text), String)
        End If
    End Sub

what can be done to get rid of this error ??

Viewing all articles
Browse latest Browse all 27036

Trending Articles