'______________________________________________ ' SHOWING IMAGES USING THE DETAILS VIEW ' Ron Kessler ' At the request of Bill Vetter ' Created 8/13/2010 '______________________________________________ 'Updated 8/13/2010 'Create a helper method to display images (ShowImage) 'call the method from form_load 'Set the Picturebox sizemode to zoom (see smart tag) 'Create a handler for the InventoryBindingSource_PositionChanged event. This fires when they change records 'on the nav bar 'Call the ShowImage method from this handler 'Hide the ImageURL textbox if you want. Option Explicit On Public Class frmDetailsView Private Sub InventoryBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InventoryBindingNavigatorSaveItem.Click UpdateDB() End Sub Private Sub DetailsView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.InventoryTableAdapter.Fill(Me.InventoryDS2007Version.Inventory) ShowImage() End Sub Private Sub ShowImage() '---get image name from this textbox Dim whichImage As String = ImageURLTextBox.Text.Trim PictureBox1.ImageLocation = "..\..\images\" & whichImage End Sub Private Sub InventoryBindingSource_PositionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InventoryBindingSource.PositionChanged '---this fires when they change records '---display the new image ShowImage() End Sub Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click '---confirm delete '*****To make this work, set the DeleteItem property of the BindingNavigator to none***** Try If (MessageBox.Show("Are you sure you want to delete this item?", _ "Please Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _ MessageBoxDefaultButton.Button2)) = Windows.Forms.DialogResult.Yes Then If InventoryBindingSource.Count > 0 Then 'make sure there are records in the dataset InventoryBindingSource.RemoveCurrent() 'removes the selected item in the list of records UpdateDB() 'save changes and refresh the grid End If End If Catch ex As Exception MessageBox.Show("An error occurred while deleting this record. " & ex.Message, "Mr. Grid Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub UpdateDB() '---tell the binding source we are done editing Me.InventoryBindingSource.EndEdit() Try '---update everything in DB Me.TableAdapterManager.UpdateAll(Me.InventoryDS2007Version) MessageBox.Show("Your database has been updated") Catch ex As Exception MessageBox.Show("An error occurred while updating this record. " & ex.Message, "Mr. Grid Error", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub End Class