BUG: A new record that is added to a parent DataGrid control does not populate the foreign key column in the child DataGrid control (816227)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework) 1.0
- Microsoft ADO.NET (included with the .NET Framework 1.1)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)
SYMPTOMSIn your Windows application Windows Form, you have added two
DataGrid controls that have the Parent-Child relationship between them.
After you add a new record in the parent DataGrid, and then you click the child DataGrid to populate the foreign key column, the column value is not
displayed in the child DataGrid. The new record is displayed in the child DataGrid only after you click a different row in the parent DataGrid, and then you click the child DataGrid.CAUSEThe problem occurs because the newly added record of the
parent DataGrid is not added to the Dataset.
The relationship between the parent table and the
child table is defined in the Dataset. Therefore, the foreign key column is not populated to the child DataGrid. When you click any other parent DataGrid record, and then click the child DataGrid, the new record is added to the DataSet, and the record is displayed in the child DataGrid.RESOLUTIONTo resolve this problem, call the Refresh method of the Currency Manager for the DataSet before you click the child DataGrid. You can call the Refresh method in the RowChange event of the parent table. To do this, follow these
steps:
- Add the following code to add the event handler for the RowChange event in the Form_Load function.
Visual Basic .NET Code ' Event handler for RowChange event
AddHandler DataSetName.Tables("TableName").RowChanged, New DataRowChangeEventHandler(AddressOf Row_Changed) Visual C# .NET Code // Event handler for RowChange event
objds.Tables["authors"].RowChanged += new System.Data.DataRowChangeEventHandler(Row_Changed); - Add the following code for the RowChange event to refresh the Currency Manager:
Visual Basic .NET Code Private Sub Row_Changed(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)
' Get the Currency Manager
Dim myCurrencyManager As CurrencyManager = CType(Me.BindingContext(objds, "authors"), CurrencyManager)
' Refresh the Currency Manager
myCurrencyManager.Refresh()
End Sub Visual C# .NET Code private void Row_Changed( object sender, System.Data.DataRowChangeEventArgs e )
{
// Get the Currency Manager
CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[objds, "authors"];
// Refresh the Currency Manager
myCurrencyManager.Refresh();
}
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor more information, visit the following MSDN Web sites:
Modification Type: | Minor | Last Reviewed: | 3/9/2006 |
---|
Keywords: | kbvs2002sp1sweep kbdisplay kbCtrl kbControl kbWindowsForms kbtable kbDesigner kbDataBinding kbDatabase kbbug KB816227 kbAudDeveloper |
---|
|