Public Class frmReportoArbitraje
    Private Sub frmReportoArbitraje_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AgregarBoton()
    End Sub
    Sub AgregarBoton()
        Dim CantidadPrimeraParte As Integer = 5
        Dim CantidadTotal = 10
        Dim Index As Integer = 0


        While CantidadTotal >= Index
            Crear(Index)
            Index += 1
        End While
        Index = 0
        While CantidadTotal >= Index

            CrearFilas()

            Index += 1
        End While



        CrearColumnaBotones(Index - 1, CantidadPrimeraParte, CantidadTotal)
        Index = CantidadPrimeraParte

        While CantidadTotal > Index

            RemoverFilas(CantidadPrimeraParte + 1)

            Index += 1
        End While

    End Sub
    Sub CrearFilas()


        dgvArbitraje.Rows.Add("")

    End Sub

    Sub RemoverFilas(ByVal quitar As Integer)


        dgvArbitraje.Rows.RemoveAt(quitar)

    End Sub

    Sub Crear(ByRef Codigo As Integer)
        Dim Boton As DataGridViewButtonColumn = New DataGridViewButtonColumn()
        Dim Texto As DataGridViewTextBoxColumn = New DataGridViewTextBoxColumn()
        Boton.Name = Codigo
        Boton.HeaderText = Codigo
        Boton.Text = Codigo * 100

        Boton.UseColumnTextForButtonValue = True
        ' añadir la columna de tipo botón al DataGridView


        Texto.DefaultCellStyle.ForeColor = Color.Maroon

        Dim CantidadColumnas As Integer = dgvArbitraje.ColumnCount
        If (CantidadColumnas Mod 2 = 0) Then
            dgvArbitraje.Columns.Add(Texto)

        Else
            dgvArbitraje.Columns.Add(Boton)

        End If
    End Sub

    Sub CrearColumnaBotones(ByRef Codigo As Integer, ByVal Decremental As Integer, ByVal Incremental As Integer)




        Dim CantidadFilas As Integer = 0


        CantidadFilas = dgvArbitraje.Rows.Count



        Dim IndexFilas As Integer = 0
        Dim IndexColumnas As Integer = 0
        While IndexFilas <= Codigo
            Dim IndexCeldas As Integer = 0
            Dim CantidadCeldas As Integer = dgvArbitraje.ColumnCount
            While IndexCeldas <= Codigo


                Dim Boton2 As DataGridViewTextBoxCell = New DataGridViewTextBoxCell()
                If Decremental > IndexFilas And Decremental > IndexCeldas Then


                    If (Not (IndexCeldas = IndexFilas) And Not (IndexCeldas Mod 2 = 0)) Then
                        dgvArbitraje.Item(IndexCeldas, IndexFilas) = Boton2
                    Else
                        If (IndexCeldas = IndexFilas) Then
                            If Not IndexCeldas = 0 Then

                                If (IndexCeldas Mod 2 > 0) Then

                                    If IndexCeldas = (Decremental - 1) Then
                                        dgvArbitraje.Rows(IndexFilas - 2).Cells(IndexCeldas).Value = "Prueba"
                                        Dim Flecha As DataGridViewImageCell = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas) = Flecha
                                        dgvArbitraje.Rows(IndexFilas).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img4.png")


                                        Flecha = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch

                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas - 1) = Flecha
                                        dgvArbitraje.Rows(IndexFilas - 1).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img5.png")

                                        Flecha = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas - 2) = Flecha
                                        dgvArbitraje.Rows(IndexFilas - 2).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img6.png")
                                    Else
                                        dgvArbitraje.Rows(IndexFilas - 1).Cells(IndexCeldas + 1).Value = "Prueba"
                                        Dim Flecha As DataGridViewImageCell = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch

                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas) = Flecha
                                        Flecha = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas + 1) = Flecha
                                        Flecha = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas + 2) = Flecha


                                        dgvArbitraje.Rows(IndexFilas).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img1.png")

                                        dgvArbitraje.Rows(IndexFilas + 1).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img2.png")
                                        dgvArbitraje.Rows(IndexFilas + 2).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img3.png")
                                    End If

                                End If
                            End If
                        End If

                    End If

                Else




                    If Not (IndexCeldas = (Decremental - 1)) Then


                        If (Not ((IndexFilas - IndexCeldas) Mod 4 = 0) Or Not (Math.Abs((IndexFilas - (Decremental))) = Math.Abs((IndexCeldas - (Decremental))))) Then
                            If Not TypeOf dgvArbitraje.Item(IndexCeldas, IndexFilas) Is DataGridViewImageCell Then

                                dgvArbitraje.Item(IndexCeldas, IndexFilas) = Boton2
                            End If





                        ElseIf IndexFilas > (Decremental) Then
                            If Not TypeOf dgvArbitraje.Item(IndexCeldas, IndexFilas) Is DataGridViewImageCell Then


                                dgvArbitraje.Item(IndexCeldas, IndexFilas) = Boton2
                            End If
                        Else

                            If Not TypeOf dgvArbitraje.Item(IndexCeldas - 1, IndexFilas - 1) Is DataGridViewImageCell Then



                                dgvArbitraje.Rows(IndexFilas - 1).Cells(IndexCeldas - 1).Value = "Prueba"



                            End If
                            If Not TypeOf dgvArbitraje.Item(IndexCeldas, IndexFilas) Is DataGridViewImageCell Then






                                If Not IndexCeldas = 0 And Not IndexFilas < 3 Then



                                    If (IndexCeldas Mod 2 > 0) Then



                                        Dim Flecha As DataGridViewImageCell = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas) = Flecha
                                        dgvArbitraje.Rows(IndexFilas).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img4.png")


                                        Flecha = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas - 1) = Flecha
                                        dgvArbitraje.Rows(IndexFilas - 1).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img5.png")



                                        Flecha = New DataGridViewImageCell
                                        Flecha.ImageLayout = DataGridViewImageCellLayout.Stretch
                                        dgvArbitraje.Item(IndexCeldas + 1, IndexFilas - 2) = Flecha
                                        dgvArbitraje.Rows(IndexFilas - 2).Cells(IndexCeldas + 1).Value = Image.FromFile("C:\Users\ahernandez\Desktop\Inv\Img\img6.png")

                                    End If
                                End If
                            End If
                        End If

                    Else
                        If Not TypeOf dgvArbitraje.Item(IndexCeldas, IndexFilas) Is DataGridViewImageCell Then


                            dgvArbitraje.Item(IndexCeldas, IndexFilas) = Boton2
                        End If
                    End If
                End If
                IndexCeldas += 1

            End While
            IndexFilas += 1
        End While


    End Sub

    Private Sub DataGridView1_DataError(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) _
Handles dgvArbitraje.DataError

    End Sub

    Private Sub dgvArbitraje_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvArbitraje.CellContentClick

    End Sub

    Private Sub FlowLayoutPanel1_Paint(sender As Object, e As PaintEventArgs)

    End Sub
End Class