Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Refresh DataGrid bound to relation
 

Refresh DataGrid bound to relation

This might be a simple question, 

I have a windows form application with a dataset composed of 2 dataadapters which are connected via a datarelation.  The form displays 2 datagrids; one bound to the child table (thus showing all the rows from the child table) the other bound to the relation (thus showing only the rows related to the active parent row).

So, call the tables Parent and Child and the relation ParentChild.  Call the grids, gridChild and gridParentChild.

I want to allow the user to "add" and "remove" child rows to / from the parent.  I have been able to make this work, but how do I refresh the gridParentChild?  That is, once I add the foreign key value to gridChild and the update succeeds, the data shown in gridParentChild is not updated.  What is the best way to refresh what the grid is showing?
MigrationUser 1  Thursday, May 29, 2003 4:26 PM
I don't know much about data binding, but I refresh a binding like this:

        Dim cm As CurrencyManager
        cm = CType(DataGrid1.BindingContext.Item(DataGrid1.DataSource), CurrencyManager)
        If Not cm Is Nothing Then
            cm.Refresh()
            DataGrid1.Update()
        End If
MigrationUser 1  Friday, May 30, 2003 10:46 AM
Thank you,

I will try that out.  I accomplished my goal by clearing the datatable and then filling it.  Like this:

                DsMaster1.Child1.Clear()
                daChild.Fill(DsRDBMaster1.Child1)

A complicating factor that I left out of the original description is that the child source table is represented by two datatables in the dataset.  One instance is related to the parent datatable, the other is not.  This allows the scenario I mentioned, with one datagrid showing all child rows and another showing only the rows related to the currently selected parent.
MigrationUser 1  Friday, May 30, 2003 11:09 AM

You can use google to search for other answers

Custom Search

More Threads

• .net Framework 3.5 dataGridView header sort with VC++ 2008
• Oct. CTP Binding Source + Business Object = Binding Problem
• Datagridview::copy row including hidden column to another datagridview
• [ Resolved ] Stop DataGridView from re-drawing itself?
• Add a generated column to a strongly-typed dataset created in the designer
• delete record with the Binding Navigator, this is really too weird
• rebind datagrid in Visual C# 2003
• Help Regarding refreshing dataGridView
• Saving the Changes to DB from Datagridview
• Export columns from datagridview to Excel