Whn clicked on Add button, AddingNew event is raised, in where you can customize item to add.
http://msdn2.microsoft.com
Goran
Main Topics
Browse All Topicsi have a databound form with two controls that are bound to a typed dataset based off of a access database. The form works fine. I would like to add a new row to the dataset with predefined data. Example, when i make the form, a navigator bar is placed at the top of the form.... when clicking a new record, the new record is added however I cannot add dynamic content to that record.
I'm trying to use the tblTableBindingSource.Add(
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Whn clicked on Add button, AddingNew event is raised, in where you can customize item to add.
http://msdn2.microsoft.com
Goran
Goran
Have you actually tried that where the ultimate DataSource is a DataTable? I have, and I couldn't get it to work - although I freely admit that I did not persist with my attempts to the extent of proving that it definitely couldn't be done. The reason for that lack of persistence was this bit
>>
The new object created in the AddingNew event must be of the same type as the type contained in the list or an exception will occur. You cannot set the NewObject property when bound to a DataView or DataTable because you cannot add a new DataRowView to the list.
<<
in the link you posted. If it can be made to work, I'd love to see an example of the code that does it.
One of the reasons I don't personally make much use of the wizard generated stuff like this is because I haven't been able to hack things like that. But it may mean I'm making my life more difficult than it needs to be. So it would be useful to know if I'm missing something.
Roger
>>
And navigator's add button is correlated with bindingsource.AddNew method, not Add.
Goran
>>
I wanted to use the .add(object), .addnew works fine...
I'm going to look into Priest04's comment first.. but if i do and I modify my database, then re-add it through the wizard, is it going to recreate my dataset, the underlying procedures and remove my custom work that you are advising I should modify?
who would have thought it was that easy.... i've been picking my brain trying to use that .add()method...
With the automated code that is generated when adding the database and adding the table to the form from the dataset, i was able to simply use the code that i didn't think would work. I was, this whole time, trying to use the least amount of code possible as I thought there was an easy way to add the object like the .add() method... apparently, .add isn't very useful.
I used:
Dim dr As DataRow = DsProjectsDataSet.tblProje
dr("ProjectName") = strName
Dim dt As DataTable = DsProjectsDataSet.Tables("
dt.Rows.Add(dr)
and it updated all of my drop down controls and the source automatically....
still, anyone know how to use the .add method or why it's even there if it's unusable? I searched the internet and most everyone's question comes up with the same error i was getting... the objects need to be the same type before adding or something like that.
Cheers!
>>
anyone know how to use the .add method or why it's even there if it's unusable?
<<
My answer to the first part is "no" - at least from personal experience. As one of my earlier posts said I don't use some of the "new" VB.NET 2005 stuff simply because (I'm lazy and) I find it easier to continue to use older methods which are still there, which I know pretty well, and which avoid me having to get my head round things which don't seem as straightforward as they might be.
But the second bit is that it _is_ usable, but not (so far as I can discover) in the current - datatable as ultimate datasource - scenario. The examples in the Help files in this area don't always seem to tie in with the subject heading under which they appear, but if you follow them through (via the links where necessary) you will see that the ultimate DataSource the examples are using is not a DataTable, it is a List(of T): specifically, a List (Of DemoCustomer), a custom class derived for demo purposes. So there (I assume) .Add would work with an instance of DemoCustomer.
Roger
Business Accounts
Answer for Membership
by: SanclerPosted on 2007-07-08 at 02:52:22ID: 19439590
The object you need is whatever the object is that the list which is the DataSource for the BindingSource is composed of. In the scenario you describe that object could be a DataRow - if the DataSource is the DataTable itself - or a DataRowView - if the DataSource is a DataView.
What I would recommend, to avoid uncertainties like that, is to do the addition direct to the DataTable (because even where there is a DataView interposed, that will ultimately be passing the new row back to the DataTable). The outline method for that is
Dim dr As DataRow = myDataTable.NewRow
'now you can set whatever values you want
dr(0) = thisValue
dr("Address") = thatAddressString
'etc
myDataTable.Rows.Add(dr)
The new row won't show until the last line is hit, but then it will show (including the values that you have inserted) in the DataGridView. The "in principle" difference in approaches is that, at the moment, what you are trying to do is use a facility of the BindingSource to create the record the binding mechanism will then pass it up (to the DataGridView) and down (to the DataTable, via a DataView if there is one). Here we go to one end of the chain - the DataTable - to make the new record and then the binding mechanism will pass it all the way up through the chain to the DataGridView.
I say that is the outline method because you'll probably find that, having a strongly typed dataset, there is some specific .NewRow object that you can use in line 1 of the code above.
Roger