stewarts Posted May 16, 2003 Posted May 16, 2003 Problem: I have a Windows Form with a TabControl. The TabControl has 2 tabpages. I put a TextBox1 and a button on TabPage1 and a TextBox2 on TabPage2. TextBox2's Text property is bound to a MS Access DB Table. When I run the form, it initializes at TabPage1. I have coded the button_click event to set TextBox1.Text = TextBox2.Text. The result is that TextBox1.Text is set to nothing. If I change to TabPage2 and back to TabPage1 and then click the button, TextBox1.Text is set to the value of TextBox2.Text. Does anyone know why I can't see the value of TextBox2.Text until I click over to TabPage2 and back again? (If I have the same scenario, except that TextBox2's Text property is not bound to a DB but rather assigned a value in my code, the problem does not exist.) Thanks!!! Quote
ailzaj Posted May 16, 2003 Posted May 16, 2003 Have you put any initial value into TextBox2 from Form_Load? Like: TextBox2.Text = tblCust.Rows(0).Item("Type") ailzaj Quote
stewarts Posted May 16, 2003 Author Posted May 16, 2003 No...I have a DataAdapter and DataSet...I filled the DataSet through the DataAdapter. When I have data in DataSets like this I point to specific records with the --- Me.BindingContext(DataSetName, "TableName").Position = 0 --- statement. When I go to TabPage2 there is a value visible in the textbox; but I just can't see it when I'm on TabPage1 until I flip over to tab2 and back to tab1. Quote
ailzaj Posted May 16, 2003 Posted May 16, 2003 OK, I tried your line of code & I got the problem you were describing. But I got the result you wanted when I used the line of code I put in my earlier post. Did you try it? ailzaj Quote
*Experts* Nerseus Posted May 16, 2003 *Experts* Posted May 16, 2003 I wonder why you wouldn't just bind both textboxes to the one datasource? I haven't tried to duplicate your code, but it sounds like a bug (if two of you can get the same odd behavior). I'd write or call MS if you think it's a bug and they can tell you yes, no, or it's a "feature" not a bug :) If you have MSDN you get at least one free support call. You can use that to find out what's going on. Otherwise the calls are around $100 each (I haven't called them for a few years). -Ner 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
*Experts* jfackler Posted May 16, 2003 *Experts* Posted May 16, 2003 Maybe I can save you the $100. I had this same poblem using binding context with a calendar control. As you know, each tab control actually contains tab pages that are represented by TabPage objects. TabPage objects apparently act modally within the tab control and can accept input focus but as a modal form no other form can recieve focus until the current form is dismissed. Focus means the form or control has the ability to recieve user input from the mouse, keyboard or setfocus method. The databind text input on the textbox2 on tabpage2 is happening when you give it focus, not before, therefore, the textbox1 on tabpage1 is appropriately reflecting the state of textbox2s text property. That's not to say your code stops processing completely until you dismiss the form, only that no other form gets focus until the modal form is dismissed. To do what you described, you will probably need to give the second tab page focus and then return it to the first or, as Ner suggested, bind them both to the datasource. I think Nerseus' suggestion is the better option. Jon Quote
ailzaj Posted May 17, 2003 Posted May 17, 2003 If you databind both text boxes as Nerseus' suggested, then both text boxes have the same information on startup. But if you do want to pull the information from one textbox to another, then try that one little line of code. ailzaj Quote
stewarts Posted May 19, 2003 Author Posted May 19, 2003 To ailzaj.....How do I use the line of code you suggested? I created a DataConnection, DataAdapter, and then generated a DataSet. The textbox is bound to the data through the DataBindings/Text property. I have many bindings of this sort in my form. When describing my problem, I simplified it in order to be able to describe the actual problem occurring. I can't just databind both boxes to the same datasource...it's not that simple. In trying to use the line of code you suggested, I don't know how to define the portion you refer to as tblCust. Thanks for everyone's input!!! Quote
ailzaj Posted May 20, 2003 Posted May 20, 2003 The tblCust is the name I gave the DataTable after the Windows Form Designer generated code: Public tblCust as DataTable Public drwCust as DataRow I put the other line of code in Form1_Load. Hope this helps Ailsa Quote
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.