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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

6162 Aug 2,2003 12:13 PM Sep 8,2003 10:26 AM Windows Forms 3
loading
Tags: FAQ
funkyone
Asked On August 2, 2003 12:13 PM

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

funkyone
Replied On August 2, 2003 01:14 PM

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! :-)

china
Replied On August 2, 2003 09:27 PM

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.

Johnny Nguyen
Replied On September 8, 2003 10:26 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;