By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

Overwriting Byte Arrays from DataGridView

P: 5
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....

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

Expand|Select|Wrap|Line Numbers
  1.     Private Sub dgridBadges_RowLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgridBadges.RowLeave
  2.         If Me.IsEmpty = True Then
  3.             Me.IsEmpty = False
  4.             DeleteRecord()
  5.             DecrementBadgeNumber()
  6.         End If
  7.     End Sub

Expand|Select|Wrap|Line Numbers
  1.     Private Sub dgridBadges_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgridBadges.SelectionChanged
  2.         If Me.IsEmpty = False And Me.dgridBadges.Rows.Count > 0 Then
  3.             Dim Converter As New ImageConverter
  4.             Dim Cells As DataGridViewCellCollection
  5.             Cells = Me.dgridBadges.CurrentRow.Cells
  6.  
  7.             Badge_NumberTextBox.Text = Cells.Item(0).Value.ToString.Trim()
  8.             First_NameTextBox.Text = Cells.Item(1).Value.ToString.Trim()
  9.             Last_NameTextBox.Text = Cells.Item(2).Value.ToString.Trim()
  10.             CompanyTextBox.Text = Cells.Item(3).Value.ToString.Trim()
  11.             UNSMC_NumberTextBox.Text = Cells.Item(4).Value.ToString.Trim()
  12.             Sponsor_NameTextBox.Text = Cells.Item(6).Value.ToString.Trim()
  13.             Sponsor_DepartmentTextBox.Text = Cells.Item(7).Value.ToString.Trim()
  14.  
  15.             If Cells.Item(9).Value Is DBNull.Value Then
  16.                 Me.PhotoPictureBox.Image = Nothing
  17.             Else
  18.                 Me.PhotoPictureBox.Image = Converter.ConvertFrom(Cells.Item(9).Value)
  19.             End If
  20.  
  21.         End If
  22.     End Sub
Any help would be greatly appreciated! Thanks
Jun 3 '08 #1
Share this Question
Share on Google+
1 Reply


Dököll
Expert 100+
P: 2,364
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
Jun 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.