Copy From Datagrid to Datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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.
 
Back
Top