Search code examples
vb.nettextboxcopyingpasting

How to copy multiple textboxes text and paste that text into other textboxes?


I have some textboxes (9) and I want to copy the data from those textboxes so when I press save on my access database I can press past and have my previous data appear on the new grid line.

Is this possible?

Here is what I have so far

COPY BUTTON -

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    If SİPARİŞ_MUMARASITextBox.TextLength = 0 Then
        MsgBox("yok")
    Else
        Clipboard.SetText(İSİMTextBox.Text & TARİHTextBox.Text & SİPARİŞ_MUMARASITextBox.Text _
          & SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Text & SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Text _
          & SAYACIN_BULUNDUĞU_KAZANTextBox.Text & KUMAŞ_RENGİTextBox.Text)
    End If
End Sub

PASTE BUTTON -

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    If Clipboard.ContainsText = True Then
        İSİMTextBox.Text = Clipboard.GetText
        TARİHTextBox.Text = Clipboard.GetText
        SİPARİŞ_MUMARASITextBox.Text = Clipboard.GetText
        SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Text = Clipboard.GetText
        BOBİN_GRAMJI__gr_m2_TextBox.Text = Clipboard.GetText
        BOBİN_ÜZERİNDE_YAZAN_METRAJ__cmXmt_TextBox.Text = Clipboard.GetText
        BASKIDAKİ_TUR_SAYISITextBox.Text = Clipboard.GetText
        SAYACIN_BULUNDUĞU_KAZANTextBox.Text = Clipboard.GetText
        KUMAŞ_RENGİTextBox.Text = Clipboard.GetText
    Else
        İSİMTextBox.Clear()
        TARİHTextBox.Clear()
        SİPARİŞ_MUMARASITextBox.Clear()
        SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Clear()
        BOBİN_GRAMJI__gr_m2_TextBox.Clear()
        BOBİN_ÜZERİNDE_YAZAN_METRAJ__cmXmt_TextBox.Clear()
        BASKIDAKİ_TUR_SAYISITextBox.Clear()
        BASKIDAKİ_TUR_SAYISITextBox.Clear()
        SAYACIN_BULUNDUĞU_KAZANTextBox.Clear()
        KUMAŞ_RENGİTextBox.Clear()
    End If
End Sub

Solution

  • Using the clipboard is very likely to be the wrong approach. Instead, you could have a Class with properties for each item that you want remembered:

    Option Infer On
    ' ...
    
    Dim thingsToCopy As CopyBuffer
    
    Public Class CopyBuffer
        Property İSİM As String = ""
        Property TARİH As String = ""
        Property SİPARİŞ_MUMARASI As String = ""
        Property SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ As String = ""
        Property BOBİN_GRAMJI__gr_m2 As String = ""
        Property BOBİN_ÜZERİNDE_YAZAN_METRAJ__cmXmt As String = ""
        Property BASKIDAKİ_TUR_SAYISI As String = ""
        Property SAYACIN_BULUNDUĞU_KAZAN As String = ""
        Property KUMAŞ_RENGİ As String = ""
    End Class
    
    Private Sub bnCopy_Click(sender As Object, e As EventArgs) Handles bnCopy.Click
        If SİPARİŞ_MUMARASITextBox.TextLength = 0 Then
            MsgBox("yok")
        Else
            thingsToCopy = New CopyBuffer With
                           {.İSİM = İSİMTextBox.Text,
                            .TARİH = TARİHTextBox.Text,
                            .SİPARİŞ_MUMARASI = SİPARİŞ_MUMARASITextBox.Text,
                            .SAYACIN_BULUNDUĞU_KAZAN = SAYACIN_BULUNDUĞU_KAZANTextBox.Text,
                            .KUMAŞ_RENGİ = KUMAŞ_RENGİTextBox.Text}
    
        End If
    
    End Sub
    
    Private Sub bnPaste_Click(sender As Object, e As EventArgs) Handles bnPaste.Click
        If thingsToCopy Is Nothing Then
            ' create a new one, which will have empty text
            thingsToCopy = New CopyBuffer
        End If
    
        With thingsToCopy
            İSİMTextBox.Text = .İSİM
            TARİHTextBox.Text = .TARİH
            SİPARİŞ_MUMARASITextBox.Text = .SİPARİŞ_MUMARASI
            SAYACIN_BULUNDUĞU_KAZANTextBox.Text = .SAYACIN_BULUNDUĞU_KAZAN
            KUMAŞ_RENGİTextBox.Text = .KUMAŞ_RENGİ
        End With
    
    End Sub
    

    You appear to be pasting more things than you have copied; you will have to adjust the code to fit what is required.