Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to force numeric entry?
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00746296
Message ID:
00748084
Views:
21
As Bonnie pointed out in another message, you want to use Table NewRow() instead of BindingContext.AddNew(). Here are the steps:
' Generate an empty DataRow
Dim newRow As DataRow = myDataSet.Tables("TableName").NewRow()

' Fill in the columns you want to fill manually
newRow("MyColumn") = "my value"

' Insert the row into the DataSet
myDataSet.Tables("TableName").Rows.Add(newRow)

' Set the BindingContext of the Control to point to the new DataRow
Me.BindingContext(myDataSet, "TableName").Position = myDataSet.Tables("TableName").Count - 1
Here is a chapter from a book that does a good job of explaining how data binding works:

http://www.bluevisionsoftware.com/WebSite/Books/CustomControlsAndDesigners/Samples/Chapter6.pdf


>Cathi can you give me your opnion in this please.
>
>I am using DataBinding to bind my DS to my WindowsForms Objects, in fact I hate the databinding but I see it usefull in one thing which is less code!! & not more than that, any how....
>
>When I add a new row to my DS, I have no problem (if I don't have to update any field manualy) if I do, I have to add 2 rows and at the end of the stage I remove one of them, I don't see it as practical. the resone for that, I am using the next code to add new row and reset the form field at the same time:
>
>Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
> With BindingContext(myDS, "Company")
> .AddNew()
> .Position = .Count - 1
> cbSelect.SelectedIndex = .Count - 1
> End With
>End Sub
>
>the advantage of this code is because of databinding the text field in the form will be empty because it will be binded to a new row.
>
>But if I want to add values to some fields manualy at the same time, it will not allow me.
>So, I have to add the following code with the above code, when Save button click:
>
>With myDS.Tables("Company")
> Dim tmpDR As DataRow = .NewRow
> tmpDR("CompanyID") = strCompanyID
> tmpDR("Entered") = Now
> tmpDR("companyname_e") = Me.txtCompanyName_e.Text
> tmpDR("Email") = Me.txtEmail.Text
> tmpDR("PostalAddress_e") = Me.rtbPostal.Text
> tmpDR("Location_e") = Me.rtbLocation.Text
> .Rows.Add(tmpDR)
>End With
>
>This way 2 rows added to the DS, so I delete the first added row:
>' The added Row in the "Add" Sub will be removed
>With BindingContext(myDS, "Company")
> .RemoveAt(iRow)
>End With
>
>Do you have any idea to allow me to use databinding & manual if adding method?
>
>BR
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform