bindingsource_addingnew event for creating default values

S

schlagenhauf

Hello Group,

being relatively new to ADO.NET (and using whidbey nonetheless)
seemingly strange things continue to happen in my app. Most of them are
dealt with by reading more about .net, but this one keeps bugging me.

Here's the story.

I'm calling a form from my main form (newform.show) and tell it that it
should create a new record (newform.mytablebindingsource.addnew).

In the Load Event in the new form, I fill my dataset by using a
parameterized query like
myTableTableAdapter.FillByPKey(myDataset.myTable,1)

Then I use the adding_new event as follows:

Private Sub BeratungenBindingSource_AddingNew(ByVal sender As
System.Object, ByVal e As System.ComponentModel.AddingNewEventArgs)
Handles myTableBindingSource.AddingNew
Dim bSrc As BindingSource = CType(sender, BindingSource)
Dim aView As Data.DataView = CType(bSrc.List, Data.DataView)
If (Not aView Is Nothing) Then
Dim aDrv As Data.DataRowView = CType(aView.AddNew,
Data.DataRowView)
If (Not aDrv Is Nothing) Then
Dim aRow As myDataSet.myTableRow = CType(aDrv.Row,
myDataSet.myTableRow)
aRow.aFKey = 1
aRow.bFKey = 10
e.NewObject = berDrv
bSrc.MoveLast()
End If
End If
End Sub

The idea is to end up in this form with all the Foreign Keys correctly
set. It works out beautifuly when a record already exists, but it won't
work when the binding source is empty - dataview.addnew does not seem
to work in this setting. I don't want to use EndEdit here, because the
row should be completed by the user.

Any guidance is welcome.


Thanks,

Jan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top