Public Class usrcntlMittagsmenues

    Private Sub usrcntlMittagsmenues_Load(sender As Object, e As EventArgs) Handles Me.Load
        LoadDGV()
    End Sub


    Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click, dgvMittagsmenu.CellDoubleClick
        Dim menu As New cMenu
        menu.loadMenu(dgvMittagsmenu.CurrentRow.Cells("MenuID").Value)
        Dim rowindex As Integer = dgvMittagsmenu.CurrentRow.Index
        Dim bearbeiten As New frmMenu
        bearbeiten.menu = menu
        AddHandler bearbeiten.FormClosing, Function()
                                               LoadDGV()
                                               dgvMittagsmenu.Rows(rowindex).Selected = True
                                               BringToFront()
                                           End Function
        bearbeiten.ShowDialog()

    End Sub

    Private Sub btnDel_Click(sender As Object, e As EventArgs) Handles btnDel.Click
        Dim menutodelete As New cMenu
        menutodelete.MenuID = dgvMittagsmenu.CurrentRow.Cells("MenuID").Value
        menutodelete.Delete()
        LoadDGV()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim debug As New Form1
        debug.Show()
    End Sub

    Function LoadDGV()
        Dim ds As New DataSet
        cSQL.SQL2DS("SELECT MenuDateVon, MenuDateBis, MenuTitel, MenuID FROM GMenu ORDER BY MenuDateVon DESC", ds)

        With dgvMittagsmenu
            .MultiSelect = False
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect

            .DataSource = ds.Tables(0)

            .Columns("MenuDateVon").HeaderText = "Von"
            .Columns("MenuDateVon").Width = 65

            .Columns("MenuDateBis").HeaderText = "Bis"
            .Columns("MenuDateBis").Width = 65

            .Columns("MenuTitel").HeaderText = "Titel"
            .Columns("MenuTitel").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

            .Columns("MenuID").Visible = False
        End With
    End Function



    Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles btnNew.Click
        Dim NeuesMenu As New frmMenu
        NeuesMenu.menu = New cMenu
        AddHandler NeuesMenu.FormClosing, Function()
                                              LoadDGV()
                                              '   dgvMittagsmenu.Rows(dgvMittagsmenu.CurrentRow.Index).Selected = True
                                          End Function
        NeuesMenu.Show()
    End Sub


End Class
