Update datasource from unbound datagridview

Hi Experts,
I have a DataGridView (RadGridView) that I fill with data from several datatables (SQL datasource). All the data displayed is unbound.

After a user made changes in the GridView I need to update the unbound datatable. My approach is to use the unique "ProductID" shown in the GridView to find the corresponding DataRow in the DataTable and for instance update the "status" of this DataRow.

I am not able to create the code that uses the "ProductID" from the GridView to update the DataRow in the DataTable with the corresponding "ProductID".

Help is appreciated.
Regards, Mark

Dim MatchingRows() As DataRow = Nothing
MatchingRows = MainForm.DS.Tables("Products").Select("ProductNumber=" & Me.rgvProducts.CurrentRow.Cells("ProductNumber").Value)
Dim ProductID As Integer = CInt(MatchingRows(0).Item("ProductID"))
MainForm.DS.Tables("Products").Rows(ProductID).Item("Status") = 40 'THIS DOES NOT WORK
mark_norgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
What do you mean by unbound grid? I think the grid is bound to the datatable in memory and in that case the rows in datatable are automatically updated although the backend database would not be updated.
0
mark_norgeAuthor Commented:
Thank you for the reply.
I create the columns for the GridView and then add the cells values with the code below. The reason for doing so is that I want to show data from several tables in a "flat" table (no hierarchy). I assume this is called unbound.

I can select, modify or add values in the GridView, but I am not able to update the datatable(s). What I would like to know is: Having the ProductID from the GridView, how to select the datarow in the datatable with the corresponding ProductID. If I know that, I can update the DataTable.

Regards, Mark



 Private Sub AddRowToProductionRadGridView(ByVal TargetRadGridView As RadGridView, ByVal RowNumber As Integer)
        Dim rowInfo As GridViewRowInfo = TargetRadGridView.Rows.AddNew()
        rowInfo.Cells(0).Value = MainForm.DS.Tables("Products").Rows(RowNumber).GetParentRow("Shippers_Products").Item("Shipper").ToString
        rowInfo.Cells(1).Value = MainForm.DS.Tables("Products").Rows(RowNumber).Item("Product").ToString
        rowInfo.Cells(2).Value = MainForm.DS.Tables("Products").Rows(RowNumber).Item("Status").ToString
        rowInfo.Cells(3).Value = CInt(MainForm.DS.Tables("Products").Rows(RowNumber).Item("ProductNumber"))
        rowInfo.Cells(4).Value = MainForm.DS.Tables("Products").Rows(RowNumber).Item("Production").ToString
        rowInfo.Cells(5).Value = MainForm.DS.Tables("Products").Rows(RowNumber).Item("Size").ToString
        rowInfo.Cells(6).Value = MainForm.DS.Tables("Products").Rows(RowNumber).Item("Quality").ToString
        rowInfo.Cells(7).Value = CInt(MainForm.DS.Tables("Products").Rows(RowNumber).Item("DefaultBoxesPerPallet"))
        rowInfo.Cells(8).Value = CInt(MainForm.DS.Tables("Products").Rows(RowNumber).Item("DefaultNetBoxWeight"))
        rowInfo.Cells(9).Value = CInt(MainForm.DS.Tables("Products").Rows(RowNumber).Item("DefaultGrossBoxWeight"))
    End Sub
0
CodeCruiserCommented:
You can do that by using the RowFilter property. For example,

dProducts.DefaultView.RowFilter="ProductID=" & ProdID
if dProducts.DefaultView.Count=1 then
   dProducts.DefaultView.Item(0).Item("Description")=txtDescription.text
end if

dProducts.DefaultView.RowFilter=""
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mark_norgeAuthor Commented:
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.