Copy From Datagrid to Datagrid

G

Guest

I have 2 datagrids, dg1 and dg2, both attached to different tables. The application is for something like an order entry system, where all available items are in dg2, and a user can either dbl click or hit a button to copy the selected row from dg2 to dg1.

I can set up a DataRow and set the values for each cell manually and insert into dg1, but for some reason cannot figure out how to extract the values from dg2 to put into that DataRow for insertion.

Here is my current code:

Dim key As String = Me.DataGridView2.SelectedCells.Item(1).RowIndex

ItemOrdered = Me.SNDBDataSet.Menu.FindByMenuItemID(key).MenuItemName()
ItemType = Me.SNDBDataSet.Menu.FindByMenuItemID(key).MenuItemType()
ItemPrice = Me.SNDBDataSet.Menu.FindByMenuItemID(key).MenuItemPrice()
ItemTranslation = Me.SNDBDataSet.Menu.FindByMenuItemID(key).MenuItemTranslation()

When I run this, it throws a "StrongTyping_CannotAccessDBNull"

Does anyone know what that means?
 
G

Guest

Figured it out.

Changed code to:

ItemOrdered = Me.DataGridView2.SelectedRows.Item(0).Cells(1).Value
ItemType = Me.DataGridView2.SelectedRows.Item(0).Cells(2).Value
ItemPrice = Me.DataGridView2.SelectedRows.Item(0).Cells(4).Value
ItemTranslation = Me.DataGridView2.SelectedRows.Item(0).Cells(3).Value

Which worked like a charm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top