Modificacion de un formulario main con databindings

Hola de nuevo, mi pregunta esque estoy haciendo un ejercicio en principio simple, pero como siempre cuando quiero ponerle yo alguna funcionalidad extra no se como hacerlo, es un foemulario main con un listbox para items,un textbox para una descripcion y un picturebox para una imagen, todos ellos cojen los datos de un dataset mediante la propiedad databinding, luego hay un formulario para añadir nuevos registros con su nombre,descripcion y su foto con un boton load para buscar imagenes en mis documentos,que funciona bien, pero lo que yo quiero hacer es modificar esos datos mediante otro formulario o algo asi, o el mismo de añadir puede servir pero recuperando los datos mediante la lista de items y he probado varias cosas y no se hacerlo te paso el codigo y aver si me puedes hechar una mano, gracias.
formulario main:
Public Class FormMain
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Items_TableTableAdapter.Fill(Me.ItemsDatabaseDataSet.Items_Table)
End Sub
Private Sub DeleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteToolStripMenuItem.Click
If Me.lstItems.SelectedIndex < 0 Then
MessageBox.Show("Please select an item for deletion...", "Tracking Application", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Dim iid As Long
iid = System.Convert.ToInt64(Me.lstItems.Tag)
Dim name As String
name = Me.lstItems.Text
Dim result As DialogResult
Dim msg As String
msg = "Are you sure you want to delete item '" & name & "'?"
result = MessageBox.Show(msg, "Tracking Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If result = Windows.Forms.DialogResult.No Then
Return
End If
Me.Items_TableTableAdapter.Delete(iid, name)
Me.Items_TableTableAdapter.Fill(Me.ItemsDatabaseDataSet.Items_Table)
MessageBox.Show("Item deleted.", "Tracking Application", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub AddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToolStripMenuItem.Click
Dim frm As FormAdd
Dim result As DialogResult
frm = New FormAdd()
result = frm.ShowDialog()
If result = Windows.Forms.DialogResult.Cancel Then
MessageBox.Show("Add cancelled...", "Tracking Application", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim name, description As String
Dim image As Byte()
name = frm.ItemName
description = frm.ItemDescription
image = frm.ItemImage
Me.Items_TableTableAdapter.Insert(name, description, image)
Me.Items_TableTableAdapter.Fill(Me.ItemsDatabaseDataSet.Items_Table)
MessageBox.Show("Item added to database!", "Tracking Application", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub ModificarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModificarToolStripMenuItem.Click
' FormAdd.Show()
End Sub
End Class

formulario add new item:
Public Class FormAdd
Private m_ItemName As String
Private m_ItemDescription As String
Private m_ItemImage As Byte()
Public ReadOnly Property ItemName() As String
Get
Return Me.m_ItemName
End Get
End Property
Public ReadOnly Property ItemDescription() As String
Get
Return Me.m_ItemDescription
End Get
End Property
Public ReadOnly Property ItemImage() As Byte()
Get
If Me.pboxImage.Image Is Nothing Then ' there is no image to return:
Return Nothing
ElseIf Me.m_ItemImage IsNot Nothing Then ' there is an image, and we have bytes already:
Return Me.m_ItemImage
Else ' we have an image, but this is the first call to get underlying bytes:
Dim ms As System.IO.MemoryStream
Dim image As System.Drawing.Image
ms = New System.IO.MemoryStream()
image = Me.pboxImage.Image
image.Save(ms, image.RawFormat)
Me.m_ItemImage = ms.GetBuffer()
Return Me.m_ItemImage
End If
End Get
End Property
Private Sub FormAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.m_ItemName = ""
Me.m_ItemDescription = ""
Me.m_ItemImage = Nothing
End Sub
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click

Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub
Private Sub cmdLoadImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadImage.Click

Dim result As System.Windows.Forms.DialogResult
Me.OpenFileDialog1.Filter = "Pictures (*.JPG;*.BMP)|*.JPG;*.BMP"
Me.OpenFileDialog1.FileName = ""
result = Me.OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.Cancel Then
Return
End If
Me.pboxImage.Image = System.Drawing.Image.FromFile(Me.OpenFileDialog1.FileName)
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click

If Me.txtName.Text = "" Then
MessageBox.Show("You must enter a name for the item...", "Tracking Application", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.txtName.Focus() ' move focus so user can enter name:
Return
End If
Me.m_ItemName = Me.txtName.Text
Me.m_ItemDescription = Me.txtDescription.Text
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
Private Sub BtnModifi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModifi.Click
End Sub
End Class
y el dataset que tiene un tableadapter simple como este :
SELECT IID_PK, Name_F, Description_F, Image_F FROM dbo.Items_Table
como ves se almacena en la base de datos dbo.Items_Table
si esto fuera modificar datos desde un grid no tendria problemas pero esto se me escapa, gracias por anticipado.

1 Respuesta

Respuesta
1
Gracias por compartirlo con los demas

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas