Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

Does somebody know about this problem :

 

I have two textbox controls witch I want to bind to my datasource (this contains only one row). I can edit the record (with beginEdit and EndEdit), but when I post 'rejectchanges' to the dataset the binding doesn't seem to affect the changes back to my textboxes.

 

PS : When is the best time for setting BeginEdit. Do I have to set this in every Onclick event of my textboxes ?

 

Thanks

  • 2 weeks later...
Posted

You probably want to put back values from row back into text boxes!? To do this try :

dim cm as system.windows.forms.currencymanager

cm=me.bindingcontext(MyDataSet.Tables("MyDataTable"))

cm.refresh()

 

If it does not work try replacing bindingcontext call parameters with (MyDataSet,"MyDataTable")

Posted (edited)

Thanks,

 

But it is not working all the time.

Problem : I have a dataset with 4 tables, 3 of them are only allowed to have maximum one single row. I've managed to use the currencymanager for single row tables but when I have to add a new row things go badly wrong.

 

Situation: 1 textbox (txtone)

In the Enter_event following code:

 Dim Mbase As BindingManagerBase = Me.BindingContext(Me.dsAanvraagdata, "Dossiers.labelpunt")

       If Mbase.Count = 0 Then

           Dim nrow As Rows.LabelpuntRow = _
               Me.dsAanvraagdata.Labelpunten.NewLabelpuntRow

           nrow.SetParentRow(Me.dsAanvraagdata.Dossiers.DossierRow(0))

           Me.dsAanvraagdata.Labelpunten.AddRow(nrow)

           Mbase.Position = 0

           Dim cm As CurrencyManager = CType(Mbase, CurrencyManager)

           cm.Refresh()

       End If

in Leave_event : 
       Dim Mbase As BindingManagerBase = Me.BindingContext(Me.dsAanvraagdata.Tables("LabelPunten"))

       Dim cm As CurrencyManager = CType(Mbase, CurrencyManager)

       cm.EndCurrentEdit()

When I enter and leave the textbox several times the text property clears itself although the text is saved in the dataset.

The events of RowChanged are also not fired when I change the text.

 

Greetings

Edited by Robby
Posted (edited)

Real code example

 

Datasource : 3 dataTables

Form : 3 textboxes, each binded to one datatable, + 2 buttons

 

Merge doesn't work after clicking button2 ??

 

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Dim System As New Aanvraagsystem()

       Dim tempds As New Aanvraagdata()

       tempds = System.GetbyDossierId(1)

       Me.dsAanvraagdata.Merge(tempds, False)


   End Sub

   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

       TextBox3.DataBindings("Text").BindingManagerBase.EndCurrentEdit()

       If Me.dsAanvraagdata.GetChanges Is Nothing Then
           MessageBox.Show("False")
       Else
           MessageBox.Show("True")

           MessageBox.Show(Me.dsAanvraagdata.Labelpunten.LabelpuntRow(0).plaats)

       End If


   End Sub

   Private Sub TextBox3_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.Enter

       If TextBox3.DataBindings("Text").BindingManagerBase.Count = 0 Then
           TextBox3.DataBindings("Text").BindingManagerBase.AddNew()
       End If

   End Sub

 

Please use

 tags [/vb ] around your code.[/color]
Edited by Robby

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...