Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Passing state\data between forms

I just finished reading yet another article\post on ways to do this in .Net.

Call me stupid, but I never gave it much thought. I always pass BindingContext and DataSets back and forth. Works well, saves writing a lot of custom properties and the like.

For example, in the parent form:

    Dim bc As New BindingContext

    Dim result As DialogResult

    bc = Me.BindingContext

    Dim frmUnlink As New frmUnlinkFirm(bc, dsSearch)

    result = frmUnlink.ShowDialog(Me)

Once the 2nd form is done, I can use both types (DataSet and BindingContext) again to do anything I have to do back in the calling form.

Is there something wrong with this approach? I never see this mentioned in 'how to' articles or posts.

3 Comments

  • What is 'frmUnlink' and 'frmUnlinkFirm'?

  • frmUnlink is the modal form being called, just copied from our production app, could be "Form1" or "Form2".

  • Just FYI - the better way to do it in .NET 2.0 is to use a BindingSource in the parent form and pass a reference to it to the child form. Same basic concept under the covers, but a little cleaner since you are not "leaking" internal details of the parent form out.

Comments have been disabled for this content.