TabControl Losing Data

G

Guest

I have a TabControl that is on a form that is bound to a DataSet. I bind the
dataset to the form in the Form_Load event. The TabControl has 2 TabPages.
The first TabPage contains a button and a textbox.

Scenario 1:
I call BindingContext(ds.TableName).AddNew(), then I click the button and
that populates some text into the textbox on the first tab. Then I switch
over to Tab2 and back to Tab1. The text that was programatically inserted is
now gone.

Scenario 2:
I do NOT call BindingContext(ds.TableName).AddNew(), then I click the button
and that populates some text into the textbox on the first tab. Then I
switch over to Tab2 and back to Tab1. The text that was programatically
inserted is still there.


I want the form to work like it does in Scenario 2, but without calling
AddNew() my DataSet will not show HasChanges.

Aside from calling BindingContext(ds.tablename).EndCurrentEdit() after
clicking on the button to populate the textbox, is there any way to keep this
data on the form?

PS - I understand that the TabControl does not bind its data to the controls
until each TabPage is shown. Could it be that the TabControl is trying to
re-bind the data on TabPage1 when I come back to it and therefore it shows no
data?
 
G

Guest

From what I have found, setting each TabPage's BindingContext property equal
to the Form's BindingContext it works. I did this on Form_Load and it
appears to be working as I thought it should.

Aspnot
 
C

Cor Ligthert [MVP]

ASPNot,
From what I have found, setting each TabPage's BindingContext property
equal
to the Form's BindingContext it works. I did this on Form_Load and it
appears to be working as I thought it should.


Than this is a greath catch because this is a long existing problem

:)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top