bortolano Posted August 5, 2003 Posted August 5, 2003 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. Quote
*Experts* Nerseus Posted August 5, 2003 *Experts* Posted August 5, 2003 If you're using bound controls, never set the control's Text property as it won't update the dataset. Instead, set the dataset's value, which will automatically reflect in the bound control. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
bortolano Posted August 6, 2003 Author Posted August 6, 2003 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 can't do this in the database itself as the "Default" values depend on the user and are dynamic (e.g., one of them is the User's name). I am trying to keep the ability to ignore the record if the user doesn't 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. Quote
bortolano Posted August 6, 2003 Author Posted August 6, 2003 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 :) Quote
*Experts* Nerseus Posted August 6, 2003 *Experts* Posted August 6, 2003 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 won't be able to use the BindingContext to add a row though - you'll have to use the original DataTable. Try something like: 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 can't remember offhand. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.