Question Adding and removing image columns in Datagridview

pedrinbr

New member
Joined
Jul 30, 2013
Messages
1
Programming Experience
Beginner
Hi everyone,

I?m having the following problem. I have a windows form application with 2 main forms, one of them is master form and the second one is the UNDO form, in the first form i input images in the datagridview based on the numeric key pressed, the second form is the undo form where i can delete the column that has the wrong value to continue inserting new values(Images). The problem is, the input works ok, but when i use the undo everything goes to hell, the grid loses it?s column names and after that inserting new values causes a lot of errors. Thanks every one for the help.

The form 1 code is bellow.
VB.NET:
 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown


        Select Case e.KeyCode
            Case Keys.NumPad7 'Resultado para dragon


                dgv_totais.CurrentCell = Nothing
                'dgv_totais.ColumnHeadersVisible = False
                'dgv_totais.RowHeadersVisible = False


                If txt_col_fullResult.Text = "0" Then


                    dgv_totais.Rows(0).Cells(0).Value = Image.FromFile("C:\Display\Images\vermelho.bmp")
                    dgv_totais.Rows(1).Cells(0).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    dgv_totais.Rows(2).Cells(0).Value = Image.FromFile("C:\Display\Images\branco.bmp")


                    Dim fulltie As New DataGridViewImageColumn() With {.Width = 52, .Name = Val(txt_col_fullResult.Text) + 1}
                    dgv_totais.Columns.Add(fulltie)


                    dgv_totais.FirstDisplayedScrollingColumnIndex = txt_col_fullResult.Text


                    lbl_totDragon.Text = Val(lbl_totDragon.Text) + 1
                    txt_Tot_dragon.Text = lbl_totDragon.Text
                    txt_col_fullResult.Text = Val(txt_col_fullResult.Text) + 1
                    txt_undo.Text = txt_col_fullResult.Text
                    'txt_undo.Text = Val(txt_col_fullResult.Text) + 1
                    txt_ver_last.Text = "1"


                    frm_resultado.Show()


                Else


                    'dgv_totais.ColumnHeadersVisible = False
                    'dgv_totais.RowHeadersVisible = False


                    dgv_totais.Rows(0).Cells(txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\vermelho.bmp")
                    dgv_totais.Rows(1).Cells(txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    dgv_totais.Rows(2).Cells(txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")


                    lbl_totDragon.Text = Val(lbl_totDragon.Text) + 1


                    Dim fulltie As New DataGridViewImageColumn() With {.Width = 52, .Name = Val(txt_col_fullResult.Text) + 1}
                    dgv_totais.Columns.Add(fulltie)


                    dgv_totais.FirstDisplayedScrollingColumnIndex = txt_col_fullResult.Text
                    txt_col_fullResult.Text = Val(txt_col_fullResult.Text) + 1
                    txt_Tot_dragon.Text = lbl_totDragon.Text
                    txt_undo.Text = txt_col_fullResult.Text
                    'txt_undo.Text = Val(txt_col_fullResult.Text) + 1
                    txt_ver_last.Text = "1"


                    frm_resultado.Show()


                End If


                dgv_totais.Rows(1).Cells(txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                dgv_totais.Rows(2).Cells(txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                dgv_totais.Rows(0).Cells(txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")

            Case Keys.NumPad3


                frm_undo.Show()


            Case Keys.NumPad4


                frm_newShoe.Show()


        End Select


    End Sub

The form 2 code

VB.NET:
 Private Sub frm_undo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.Return


                '-------------------------------------------------------------------------------------------------------------------------------
                '+++++ DRAGON ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                '-------------------------------------------------------------------------------------------------------------------------------


                If frm_main.txt_ver_last.Text = "1" And frm_main.txt_Tot_dragon.Text = "1" Then


                    'frm_main.dgv_totais.Columns.RemoveAt(0)
                    'frm_main.dgv_totais.Update()


                    frm_main.dgv_totais.Rows(0).Cells(0).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    frm_main.dgv_totais.Rows(1).Cells(0).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    frm_main.dgv_totais.Rows(2).Cells(0).Value = Image.FromFile("C:\Display\Images\branco.bmp")


                    'Dim fulltie As New DataGridViewImageColumn() With {.Width = 52, .Name = frm_main.txt_col_fullResult.Text}
                    'frm_main.dgv_totais.Columns.Add(fulltie)


                    frm_main.dgv_totais.FirstDisplayedScrollingColumnIndex = Val(frm_main.txt_col_fullResult.Text) - 1
                    frm_main.lbl_totDragon.Text = Val(frm_main.lbl_totDragon.Text) - 1
                    frm_main.txt_col_fullResult.Text = "1"
                    frm_main.txt_Tot_dragon.Text = "0"
                    frm_main.txt_undo.Text = Val(frm_main.txt_col_fullResult.Text) + 1


                    frm_main.txt_ver_last.Text = "0"
                    Me.Close()


                End If


                If frm_main.txt_ver_last.Text = "1" And frm_main.txt_Tot_dragon.Text > "1" Then


                    frm_main.dgv_totais.Columns.RemoveAt(Val(frm_main.txt_col_fullResult.Text) - 1)


                    'frm_main.lbl_totDragon.Text = Val(frm_main.lbl_totDragon.Text) - 1
                    frm_main.txt_Tot_dragon.Text = Val(frm_main.txt_Tot_dragon.Text) - 1
                    'frm_main.txt_undo.Text = frm_main.txt_col_fullResult.Text
                    'frm_main.txt_col_fullResult.Text = Val(frm_main.txt_col_fullResult.Text) - 1
                    frm_main.dgv_totais.Rows(0).Cells(frm_main.txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    frm_main.dgv_totais.Rows(1).Cells(frm_main.txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    frm_main.dgv_totais.Rows(2).Cells(frm_main.txt_col_fullResult.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")


                    'frm_main.dgv_totais.Rows(0).Cells(frm_main.txt_undo.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    'frm_main.dgv_totais.Rows(1).Cells(frm_main.txt_undo.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")
                    'frm_main.dgv_totais.Rows(2).Cells(frm_main.txt_undo.Text).Value = Image.FromFile("C:\Display\Images\branco.bmp")


                    frm_main.txt_col_fullResult.Text = Val(frm_main.txt_col_fullResult.Text) - 1


                    frm_main.txt_ver_last.Text = "0"
                    Me.Close()


                End If

Case Else


                Me.Close()


        End Select


        Me.Close()


    End Sub
 
Back
Top