MINDSUPERB
asked on
Insert data into a table after selecting a record in a data grid view
Hi all!
I am using VB 2008 Express.
I have two tables: tblInventory and tblTransactions. tblInventory has fields: ID, ItemNo, ItemDescrtiption, QuantityInStock, and Cost while tblTransaction has ID, ItemNo, ItemDescription, TransactionType, Date, and Quantity.
I created a form (frmInventory) with a Filter feature to only display the Items in the Datagrid View which match the criteria in a filter box.
What I wish to happen, after the filtering, is that: when an item/record is clicked from the datagrid view in frmInventory, my other form, frmTransaction will show and the selected data will automatically populate on the fields particularly the ItemNo and ItemDescription.
Any suggestion and solution you will give is highly appreciated.
Thank you.
Ed
I am using VB 2008 Express.
I have two tables: tblInventory and tblTransactions. tblInventory has fields: ID, ItemNo, ItemDescrtiption, QuantityInStock, and Cost while tblTransaction has ID, ItemNo, ItemDescription, TransactionType, Date, and Quantity.
I created a form (frmInventory) with a Filter feature to only display the Items in the Datagrid View which match the criteria in a filter box.
What I wish to happen, after the filtering, is that: when an item/record is clicked from the datagrid view in frmInventory, my other form, frmTransaction will show and the selected data will automatically populate on the fields particularly the ItemNo and ItemDescription.
Any suggestion and solution you will give is highly appreciated.
Thank you.
Ed
ASKER
How are these tables related?
They are related by ItemNo.
There is a missing field in tblTransaction that I forgot to include. That is InventoryID.
May I ask how to initialize the frmTransaction and how to pass the ID into another form? Sorry, I am still on the process of learning VB.
thanks.
They are related by ItemNo.
There is a missing field in tblTransaction that I forgot to include. That is InventoryID.
May I ask how to initialize the frmTransaction and how to pass the ID into another form? Sorry, I am still on the process of learning VB.
thanks.
In the frmInventory, Once you insert the Inventory record,You will be having ItemNo.
--This part is in frminventory
In the Datagridview click event
Dim objTrans As New frmTransaction
objTrans.Initialize(IItemN o)
objTrans.Show()
-- In frmTransaction
Dim TransItem As Datatype
Public Sub Initialize(ByVal ItemNo As Datatype)
TransItem = ItemNo
EndSub
Private sub frm_Load()
Get the data as dataset from datatable with the itemNo and populate all fields
End Sub
--This part is in frminventory
In the Datagridview click event
Dim objTrans As New frmTransaction
objTrans.Initialize(IItemN
objTrans.Show()
-- In frmTransaction
Dim TransItem As Datatype
Public Sub Initialize(ByVal ItemNo As Datatype)
TransItem = ItemNo
EndSub
Private sub frm_Load()
Get the data as dataset from datatable with the itemNo and populate all fields
End Sub
Here are the events you can use and in the following fashion. Form2 indicates frmtransaction
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim f2 As New Form2
f2.Init(DataGridView1.Rows(e.RowIndex).Cells("txt").Value.ToString)
f2.Show()
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
Dim f2 As New Form2
f2.Init(DataGridView1.Rows(e.RowIndex).Cells("txt").Value.ToString)
f2.Show()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am sorry for my delayed response.
Initialize frmTransaction with the ID from frmInventory. When a row is selected, pass the ID to frm transaction and when form loads get the data from table to populate in the fields.