Tab Control Erases Data

bortolano

Member
Joined
Jul 25, 2003
Messages
6
I have a series of bound controls located on two pages of a tab control on a form. Lets say TextBox1 is on TabPage1 and TextBox 2 is on TabPage2. Both are bound to a DataSet.
If I type in Textbox 1 and then click to TabPag2 and come back to TabPage1, whatever I typed is there.
However, if I set the value of Textbox1.Text to a value in code in the Form_Load event, then click to TabPage2, when I come back to TabPage1, all my data is gone. However, the items I typed by hand still persist.
Has anyone run into this and, if so, is there a work-around. Several of the data screens I am creating have too many fields to appear on one form and I need an option to show one "Screen" of information at a time.

Thanks.
 
If youre using bound controls, never set the controls Text property as it wont update the dataset. Instead, set the datasets value, which will automatically reflect in the bound control.

-nerseus
 
Setting Default Values of New Record

How would I set the "default" values in code using the BindingContext to move to a new record. If I have -

BindingContext(dsDataSet, "tblSomeTable").AddNew()

I was then using -

txtTextbox1.Text="SomeData"

However, that got erased when I went to Tab Page 2. How do I set the underlying Dataset to the default values. I cant do this in the database itself as the "Default" values depend on the user and are dynamic (e.g., one of them is the Users name). I am trying to keep the ability to ignore the record if the user doesnt type anything in the record (e.g. the user moves to a new record, then moves back one record without entering data), similar to what Access does natively.
 
Figured it out

Disregard, I figured it out. For anyone else having this difficulty, I set the default values I wanted by using -

dsDataSet.Tables(0).Columns("ColumnName").DefaultValue = Value

Value can be static, a variable, or even a function that returns a value. FYI in case this helps anyone else out there :)
 
That will work if you really want that value to be the default for every row, which you might. If you just want the values to be pre-populated one time, use NewRow and Add. You wont be able to use the BindingContext to add a row though - youll have to use the original DataTable. Try something like:
Code:
Dim row as DataRow = dsDataSet.Tables("tblSomeTable").NewRow()
row("ColumnName") = Value
dsDataSet.Tables("tblSomeTable").Rows.Add(row)

On the last line, the Add method might be AddRow, I cant remember offhand.

-Nerseus
 
Back
Top