Visibility of textbox.text value on tabcontrol

stewarts

Member
Joined
Apr 8, 2003
Messages
22
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. TextBox2s 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 cant see the value of TextBox2.Text until I click over to TabPage2 and back again? (If I have the same scenario, except that TextBox2s Text property is not bound to a DB but rather assigned a value in my code, the problem does not exist.)

Thanks!!!
 
Have you put any initial value into TextBox2 from Form_Load?
Like:
[VB]
TextBox2.Text = tblCust.Rows(0).Item("Type")
[/VB]
ailzaj
 
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 cant see it when Im on TabPage1 until I flip over to tab2 and back to tab1.
 
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
 
I wonder why you wouldnt just bind both textboxes to the one datasource?

I havent tried to duplicate your code, but it sounds like a bug (if two of you can get the same odd behavior). Id write or call MS if you think its a bug and they can tell you yes, no, or its a "feature" not a bug :)

If you have MSDN you get at least one free support call. You can use that to find out whats going on. Otherwise the calls are around $100 each (I havent called them for a few years).

-Ner
 
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. Thats 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
 
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
 
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 cant just databind both boxes to the same datasource...its not that simple. In trying to use the line of code you suggested, I dont know how to define the portion you refer to as tblCust. Thanks for everyones input!!!
 
The tblCust is the name I gave the DataTable
after the Windows Form Designer generated code:
[VB]
Public tblCust as DataTable
Public drwCust as DataRow
[/VB]
I put the other line of code in Form1_Load.

Hope this helps

Ailsa
 
Back
Top