Imports VERAG_PROG_ALLGEMEIN

Public Class frmAbrechnungHandling

    Dim dt As DataTable
    Dim HandlingList As cHandlingssaetzeInternLIST
    Dim title As String
    Public Sub New(dt As DataTable, HandlingList As VERAG_PROG_ALLGEMEIN.cHandlingssaetzeInternLIST, title As String)


        InitializeComponent()
        Me.dt = dt
        Me.HandlingList = HandlingList
        Me.title = title

    End Sub

    Private Sub frmAbrechnungHandling_Load(sender As Object, e As EventArgs) Handles MyBase.Load



        If dt.Rows.Count > 0 Then
            dgvHandling.DataSource = dt
        End If

        Me.Text = title

    End Sub

    Private Sub btnPreisliste_Click(sender As Object, e As EventArgs) Handles btnPreisliste.Click
        If HandlingList.LIST.Count > 0 Then

            Dim dt_temp As New DataTable()

            Dim props = HandlingList.LIST(0).GetType().GetProperties()

            ' Create columns automatically
            For Each p In props
                dt_temp.Columns.Add(p.Name, p.PropertyType)
            Next

            ' Fill rows
            For Each item In HandlingList.LIST
                Dim row = dt_temp.NewRow()

                For Each p In props
                    row(p.Name) = p.GetValue(item, Nothing)
                Next

                dt_temp.Rows.Add(row)
            Next

            dgvHandling.DataSource = dt_temp

            VERAG_PROG_ALLGEMEIN.cProgramFunctions.genExcelFromDT_NEW(dt_temp)

        End If
    End Sub
End Class