Overwriting Byte Arrays from DataGridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beagley
    New Member
    • Mar 2008
    • 5

    Overwriting Byte Arrays from DataGridView

    This error occurs when chaning the "Badge Number" field of my database, the program is taking the photo of the record that is being changed and copies it to the NEXT record in the DataGridView overwriting the photo for that particular person.

    If anyone has any kind of knowledge of working with DataGrids I would appreciate some help. Here are the pieces of code that are executed when I get the overwrite bug....

    Code:
        Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            If (Badge_NumberTextBox.Text.Length <= 0) Then
                Badge_NumberTextBox.ForeColor = Color.Red
                MessageBox.Show("Badge Number cannot be blank!", "Enter a value for the badge number", MessageBoxButtons.OK)
            Else
                dgridBadges.CurrentRow.Cells.Item(5).Value = Issue_DateDateTimePicker.Value.ToShortDateString
                dgridBadges.CurrentRow.Cells.Item(8).Value = Expiration_DateDateTimePicker.Value.ToShortDateString
                Me.Validate()
                Me.TableContractorBadgesBindingSource.EndEdit()  'this line causes execution to branch to the dgridBadges_RowLeave sub, followed by dgrid_Badges_SelectionChanged sub, then returns to here
                Me.TableAdapterContractorBadges.Update(Me.DatasetContractorBadges.Table_Contractor_Badges)
                dgridBadges.Sort(dgridBadges.Columns.Item(0), System.ComponentModel.ListSortDirection.Ascending)   'This causes the dgridBadges_RowLeave sub to execute one last time
            End If
        End Sub

    Code:
        Private Sub dgridBadges_RowLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgridBadges.RowLeave
            If Me.IsEmpty = True Then
                Me.IsEmpty = False
                DeleteRecord()
                DecrementBadgeNumber()
            End If
        End Sub

    Code:
        Private Sub dgridBadges_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgridBadges.SelectionChanged
            If Me.IsEmpty = False And Me.dgridBadges.Rows.Count > 0 Then
                Dim Converter As New ImageConverter
                Dim Cells As DataGridViewCellCollection
                Cells = Me.dgridBadges.CurrentRow.Cells
    
                Badge_NumberTextBox.Text = Cells.Item(0).Value.ToString.Trim()
                First_NameTextBox.Text = Cells.Item(1).Value.ToString.Trim()
                Last_NameTextBox.Text = Cells.Item(2).Value.ToString.Trim()
                CompanyTextBox.Text = Cells.Item(3).Value.ToString.Trim()
                UNSMC_NumberTextBox.Text = Cells.Item(4).Value.ToString.Trim()
                Sponsor_NameTextBox.Text = Cells.Item(6).Value.ToString.Trim()
                Sponsor_DepartmentTextBox.Text = Cells.Item(7).Value.ToString.Trim()
    
                If Cells.Item(9).Value Is DBNull.Value Then
                    Me.PhotoPictureBox.Image = Nothing
                Else
                    Me.PhotoPictureBox.Image = Converter.ConvertFrom(Cells.Item(9).Value)
                End If
    
            End If
        End Sub
    Any help would be greatly appreciated! Thanks
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Greetings, Beagley!

    Just pasing through but wanted to let you know to stay tuned, you're bound to get an answer. This also means I could not help in this case:-)

    Good luck... also have a great week-end Beagley, looks like a hot one here here in Upstate NY!

    Dököll

    Comment

    Working...