Martin,
I have always used the method that you show for adding new rows, but I typically do not have mine sorted, so it was never a problem. However, the way around this is to add a new row this way instead:
Me.BindingContext(ds, "Countries").AddNew()
Me.BindingContext(ds, "Countries").EndCurrentEdit()
One note ... I prefer using the other syntax of BindingContext, and that would be:
Me.BindingContext(ds.Tables("Countries")).AddNew()
Me.BindingContext(ds.Tables("Countries")).EndCurrentEdit()
They are two different BindingContexts though ... so if you're already using the first, stay with it or everything will get screwed up. I only mention it so others will see the different syntax.
~~Bonnie
>Hi all!
>
>I have a form with several textboxes that are bounded. When adding a new row I first create a DataRow object:
>
>Dim NewRow As Data.DataRow = dtCountries.NewRow
>
>
>Then I add the row to the DataTable so that I can update the row using the textboxes which are bounded to the DataTable:
>
>dtCountries.Rows.Add(NewRow)
>
>
>Then I move the position to the new row so that it will be set on the textboxes and ready for editing:
>
>Me.BindingContext(ds, "Countries").Position = dtCountries.Rows.Count - 1
>
>
>The problem is, if the records are sorted I obviously can not use this command since it will only get the last record added. If it is sorted, the last recorded added may not be the last but the first. So I just wanted to get some recommendations on how this should be handled?
>
>Another thing I would like to know. The process I mentioned above... is the proper way of adding records? Assuming that the objects on the form are bounded. I was just wondering, like, would it be possible to create a new record without attaching to the DataTable. Then have the user fill in the blanks. And then after validating the record that would be the time to add it to the DataTable. If it is possible to do this... any ideas how?
>
>Thanx! a lot in advance!
>
>Martin