Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

currencymanager addnew and unbound fields..

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
Good morning all.

I am trying to add a new record via currencymanager and bound txt controls

My question is this:
How do I set new row fields which are not bound?

I have been trying this:

ds.Tables("Provider").NewRow.Item("Name") = providername

Which is obviously incorrect. could someone here put me straight please?

cheers
(slightly more detailed code below)

<binding stuff>
thisCurrencyManager = _
CType(Me.BindingContext(ds.Tables("Provider")), CurrencyManager)

thisCurrencyManager.Position = 0
<end binding stuff>

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Try
thisCurrencyManager.EndCurrentEdit()
thisCurrencyManager.AddNew()
Catch eEndEdit As System.Exception
System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
End Try
End Sub

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
Dim providername As String = txtLname.Text & ", " & txtFname.Text
ds.Tables("Provider").NewRow.Item("Name") = providername
thisCurrencyManager.EndCurrentEdit()
DataGrid1.Refresh()
End Sub




Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Funny you should say that, thats what i was trying to do yesterday but i kept ending up with 2 new datarows, one with unbound values and one without.

It seems that CurrencyManager.AddNew() adds the new row, and creating and adding one to the dataset was adding yet another.

Anyway I answered my own question (after some eye-crossing research) and found this, which does exactly what i wanted:
Code:
 Dim drv As DataRowView = DirectCast(thisCurrencyManager.Current, DataRowView)
        drv("name") = providername
        thisCurrencyManager.EndCurrentEdit()
        thisCurrencyManager.Refresh()

Just as a comment, I am very new to .NET and VB, and it seems there are very few people out there using databinding and currencymanagers. (I say this because the only two answers I got were as you suggested, which does not work)
Would you say this is because of the opinion from the gurus that databinding is for people who dont know what they are doing? (I read that somewhere) or is the concept new since VB6?


Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top