Update datasource from unbound datagridview

Posted on 2008-11-04
Last Modified: 2012-05-05
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
Question by:mark_norge
    LVL 83

    Expert Comment

    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.

    Author Comment

    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
    LVL 83

    Accepted Solution

    You can do that by using the RowFilter property. For example,

    dProducts.DefaultView.RowFilter="ProductID=" & ProdID
    if dProducts.DefaultView.Count=1 then
    end if


    Author Closing Comment

    Thanks a lot.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now