?
Solved

Update datasource from unbound datagridview

Posted on 2008-11-04
4
Medium Priority
?
1,139 Views
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
0
Comment
Question by:mark_norge
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22884217
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
 

Author Comment

by:mark_norge
ID: 22884412
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 22884855
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
 

Author Closing Comment

by:mark_norge
ID: 31513138
Thanks a lot.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

807 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