VB.NET - Automatic TextChanged

1

Talk, guys! I am trying to perform automatic date. For example, if I choose the field year "Up" in case 2018. The "From" field automatically calculates for year 2013.

As print below:

Ihavemanagedtoautomatejustthisone.ButwhenIwanttochangethe"Until" field, from 04/18/2018 to 04/18/2015. The "From" field remains the year 2013.

WhatIwantistocalculatefive-yeardifference.

Hereismycode:

ImportsMicrosoft.Office.InteropPublicClassFormRelatorioDimXcelAppAsNewExcel.Application()'PrivateSubcarregaGrid()'Try'DimdtAsNewDataTable'dt.Columns.Add("Codigo", GetType(Integer))
    '        dt.Columns.Add("Nome", GetType(String))
    '        dt.Columns.Add("Admissao", GetType(DateTime))
    '        dt.Columns.Add("Setor", GetType(Integer))
    '        dt.Columns.Add("Salario", GetType(Double))
    '        Dim dr As DataRow = dt.NewRow()
    '        dr("Codigo") = 1
    '        dr("Nome") = "João Torres"
    '        dr("Admissao") = DateTime.Now
    '        dr("Setor") = 20
    '        dr("Salario") = 20000
    '        dt.Rows.Add(dr)
    '        dr = dt.NewRow()
    '        dr("Codigo") = 2
    '        dr("Nome") = "Jennifer"
    '        dr("Admissao") = DateTime.Now
    '        dr("Setor") = 40
    '        dr("Salario") = 20000
    '        dt.Rows.Add(dr)
    '        dgvDados.DataSource = dt
    '    Catch ex As Exception
    '        MessageBox.Show("Erro" + ex.Message)
    '    End Try
    'End Sub

    Private Sub Label3_Click(sender As System.Object, e As System.EventArgs) Handles Label3.Click

    End Sub

    Private Sub gerarBtn_Click(sender As System.Object, e As System.EventArgs) Handles gerarBtn.Click
        If dgvDados.Rows.Count > 0 Then
            Try
                XcelApp.Application.Workbooks.Add(Type.Missing)

                For i As Integer = 1 To dgvDados.Columns.Count
                    XcelApp.Cells(1, i) = dgvDados.Columns(i - 1).HeaderText
                Next
                '
                For i As Integer = 0 To dgvDados.Rows.Count - 2
                    For j As Integer = 0 To dgvDados.Columns.Count - 1
                        XcelApp.Cells(i + 2, j + 1) = dgvDados.Rows(i).Cells(j).Value.ToString()
                    Next
                Next
                '
                XcelApp.Columns.AutoFit()
                '
                XcelApp.Visible = True
            Catch ex As Exception
                MessageBox.Show("Erro: " + ex.Message)
                XcelApp.Quit()
            End Try
        End If
    End Sub

    Private Sub Relatorio_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AntaqDataSet.T400_ATRACACAO' table. You can move, or remove it, as needed.
        Dim dbase As New dBase
        Me.T400_ATRACACAOTableAdapter.Fill(Me.AntaqDataSet.T400_ATRACACAO)
        ' carregaGrid()
        dgvDados.DataSource = dbase.GetAllAtracacao()
        Dim dtEscolha As DateTime
        dtEscolha = dtpAtual.Text
        txtBoxDe.Text = dtEscolha.AddYears(-5)
    End Sub

    Private Sub MaskedTextBox2_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs)

    End Sub

    Private Sub dgvDados_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDados.CellContentClick

    End Sub

    Private Sub dtpAtual_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dtpAtual.ValueChanged

    End Sub

    Private Sub txtBoxDe_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles txtBoxDe.MaskInputRejected
        System.Diagnostics.Debug.Write(dtpAtual.Text)
    End Sub
End Class
    
asked by anonymous 18.04.2018 / 21:06

1 answer

0

ANSWER:

Include the event code dptAtual_ValueChanged:

Private Sub dtpAtual_ValueChanged(sender As System.Object, e As 
System.EventArgs) Handles dtpAtual.ValueChanged Dim dtEscolha As DateTime dtEscolha = dtpAtual.Text txtBoxDe.Text = dtEscolha.AddYears(-5) End Sub
    
22.05.2018 / 15:14