Public Class frmSearchWT
    Public WT_Nr = -1
    Public WT_LIST As VERAG_PROG_ALLGEMEIN.cZollTarifAtlas_LIST = Nothing
    Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL

    Private Sub frmSearchWT_Load(sender As Object, e As EventArgs) Handles Me.Shown
        If WT_Nr > 0 Then
            txt.Text = WT_Nr
        End If
    End Sub

    Private Sub DataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView.CellDoubleClick
        If e.RowIndex >= 0 Then
            WT_Nr = DataGridView.Rows(e.RowIndex).Cells(0).Value
            Me.Close()
        End If
    End Sub

    Private Sub txt_TextChanged(sender As Object, e As EventArgs) Handles txt.TextChanged
        If cbxAlle.Checked Then
            For Each r As DataGridViewRow In DataGridView.Rows
                If r.Cells(0).Value.ToString.StartsWith(txt.Text) Then
                    DataGridView.FirstDisplayedScrollingRowIndex = r.Index
                    'dataGridView1.Update();
                End If
            Next
        Else
            If txt.Text <> "" Then
                DataGridView.DataSource = SQL.loadDgvBySql("SELECT TOP 100 ezttxt_code,ezttxt_text FROM [ezttxt] WHERE [ezttxt_datend] >= getdate() AND ezttxt_code LIKE '" & txt.Text & "%' ORDER BY [ezttxt_code] ", "ATLAS")
            Else
                DataGridView.Columns.Clear()
            End If
        End If
    End Sub

    Private Sub cbxAlle_CheckedChanged(sender As Object, e As EventArgs) Handles cbxAlle.CheckedChanged
        If sender.checked Then
            DataGridView.DataSource = SQL.loadDgvBySql("SELECT ezttxt_code,ezttxt_text FROM [ezttxt] WHERE [ezttxt_datend] >= getdate() ORDER BY [ezttxt_code] ", "ATLAS")
        Else
            DataGridView.Columns.Clear()
        End If
    End Sub

    Private Sub DataGridView_CellContentClick_1(sender As Object, e As EventArgs) Handles DataGridView.SelectionChanged
        'If DataGridView.RowCount > 0 Then
        If DataGridView.SelectedRows.Count > 0 Then
            Dim t As New Threading.Thread(Sub()
                                              Me.Invoke(Sub() RichTextBox.Text = WT_LIST.getFullTxtByCode(DataGridView.SelectedRows(0).Cells(0).Value))
                                          End Sub)
            t.IsBackground = True
            t.Start()
        Else
            RichTextBox.Text = ""
        End If
        'End If


    End Sub

    Sub setRTB()

    End Sub

    Private Sub frmSearchWT_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        txt.Focus()
    End Sub
End Class