We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataView.AllowNew does not work in Master/Detail after scrolling through Master records

Hi there, I am having a problem disabling the automatic add row functionality on a Datagrid that is displaying related child records (from a dataset relation). First I am selecting Customers and Orders from the Northwind database and setting a relation between them in the dataset. da = New OleDbDataAdapter("SELECT * FROM Customers", cnn) da.Fill(myDataSet, "Customers") da = New OleDbDataAdapter("SELECT * FROM Orders", cnn) da.Fill(myDataSet, "Orders") myDataSet.Relations.Add("Customer_Orders", _ myDataSet.Tables("Customers").Columns("CustomerID"), _ myDataSet.Tables("Orders").Columns("CustomerID"), True) Then I bind the data to my controls on the form: Me.txtCompany.DataBindings.Add("Text", myDataSet, "Customers.CompanyName") Me.txtCustID.DataBindings.Add("Text", myDataSet, "Customers.CustomerID") Me.txtContact.DataBindings.Add("Text", myDataSet, "Customers.ContactName") Me.grdOrdersGrid.SetDataBinding(myDataSet, "Customers.Customer_Orders") Then I grab references to the Currency Managers into some form variables: Me.CmOrders = DirectCast(Me.grdOrdersGrid.BindingContext(Me.grdOrdersGrid.DataSource, Me.grdOrdersGrid.DataMember), CurrencyManager) Me.CmCustomer = DirectCast(Me.BindingContext(myDataSet, "Customers"), CurrencyManager) Then I set AllowNew to false on the Datagrid's DataView: DirectCast(Me.CmOrders.List, DataView).AllowNew = False Okay! Great that all works fine. The asterik (*) at the bottom of the grid does not display and I am not able to add records to the child. UNTIL.... I have buttons on the form for navigating through the Customers (Master) by setting the position on the customer Currency Manager. For instance, when I click the Next button on my form I issue the following: Me.CmCustomer.Position += 1 It works well, the customer controls show the new record and the datagrid updates to show the related records. BUT.. the asterik is back! The datagrid now allows automatic adds again! I set breakpoints and look at the AllowNew property and it is still set to False. I even tried setting it again and again after the position change on the customer.. still no luck! TIA, -Funkyone

3 Replies

FU funkyone August 2, 2003 05:14 PM UTC

Okay I figured it out! I found out that the child data view is recreated every time the position is changed in the parent data view so I added an Event Handler on my Customer Currency Manager to reset the DataView AllowNew property to false: Private Sub CmCustomer_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmCustomer.PositionChanged Me.SetOrdersView() End Sub Private Sub SetOrdersView() Me.DvOrders = DirectCast(Me.CmOrders.List, DataView) Me.DvOrders.AllowNew = False End Sub Thanks anyways! :-)

CH china August 3, 2003 01:27 AM UTC

Hi, i have a problem that how can i read a picture file from the openfileDialog to the Picturebox. which class I can use?Streamread or filestream? Thanks.

JN Johnny Nguyen September 8, 2003 02:26 PM UTC

Hi funkyone, I'm also working on this sample Customer-Orders detail and I could not make the AddNew function to not add a new row to the datagrid ( the asterisk). Can you post all the code that you have so I can take a look at them. And also do you know how to add a checkbox or textbox to both the master and the detail grids? Thanks a lot

Live Chat Icon For mobile
Up arrow icon