Question

Databound controls inside tabcontrol tabs do not bind until after the tab is selected! Workarounds?

Asked by: bd9000

I discovered to my horror what appears to be a bug with the TabControl that comes with VS2008 (and every 3rd party tab control on the market that derives from this).

I built a sample text table on SQL 2005 Server with 3 columns  "idx" (integer), "col1" (string) and "col2" (money)

I built a simple form with 1 TabControl with 2 tab pages.
On the first tab page I put in 2 databound textboxes.  idx & col1
On the second page, I put in a single databound textbox.  col2

There is a 4th text box outside of the TabControl that will have it's Text property changed to the text value of the databound col2 textbox when an event (does not matter the event, I've tried just about every one!) is fired (ie indexchanged, textchanged, etc.)

If a user is scrolling through records using a BindingNavigator, but does NOT click on the second tab, the col2 textbox is never filled with it's databound value!
To make matters worse, even if I programmatically change the selectedIndex of the TabControl right after the dataset is filled and then call the Refresh on the TabPages after each index, it STILL won't bind it.  A user has to manually click the mouse on the tabPage (tab) to get the controls on the page (textbox, in this example) to update their contents.

In the real application, there are 6 tabPages with 8-15 controls on each page.  Because there are 85 columns on the table, the only way to fit it into the form is to put the fields in tabPages or force the user to scroll a single page with 85 fields (not an option here).


Any ideas or workarounds?

Attached is the code below:

' Main Form *************************************
Public Class Form1
 
    Private Sub TestBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TestBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.WPMlocalDataSet)
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'WPMlocalDataSet.test' table. You can move, or remove it, as needed.
        Me.TestTableAdapter.Fill(Me.WPMlocalDataSet.test)
        'Me.TextBox1.Text = Me.Col2TextBox.Text  'can't use this unless you start on TabPage 2
 
    End Sub
 
    Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
        Me.TextBox1.Text = Me.Col2TextBox.Text 'This won't work (nor will any events from the BN unless you start on TabPage 2 or click on it first otherwise Col2TextBox.TexT is still empty)
    End Sub
End Class
 
 
' Designer ********************************************************************************************
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
 
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Dim IdxLabel As System.Windows.Forms.Label
        Dim Col1Label As System.Windows.Forms.Label
        Dim Col2Label As System.Windows.Forms.Label
        Me.TestBindingNavigator = New System.Windows.Forms.BindingNavigator(Me.components)
        Me.BindingNavigatorAddNewItem = New System.Windows.Forms.ToolStripButton
        Me.BindingNavigatorCountItem = New System.Windows.Forms.ToolStripLabel
        Me.BindingNavigatorDeleteItem = New System.Windows.Forms.ToolStripButton
        Me.BindingNavigatorMoveFirstItem = New System.Windows.Forms.ToolStripButton
        Me.BindingNavigatorMovePreviousItem = New System.Windows.Forms.ToolStripButton
        Me.BindingNavigatorSeparator = New System.Windows.Forms.ToolStripSeparator
        Me.BindingNavigatorPositionItem = New System.Windows.Forms.ToolStripTextBox
        Me.BindingNavigatorSeparator1 = New System.Windows.Forms.ToolStripSeparator
        Me.BindingNavigatorMoveNextItem = New System.Windows.Forms.ToolStripButton
        Me.BindingNavigatorMoveLastItem = New System.Windows.Forms.ToolStripButton
        Me.BindingNavigatorSeparator2 = New System.Windows.Forms.ToolStripSeparator
        Me.TestBindingNavigatorSaveItem = New System.Windows.Forms.ToolStripButton
        Me.TabControl1 = New System.Windows.Forms.TabControl
        Me.TabPage1 = New System.Windows.Forms.TabPage
        Me.TabPage2 = New System.Windows.Forms.TabPage
        Me.IdxTextBox = New System.Windows.Forms.TextBox
        Me.Col1TextBox = New System.Windows.Forms.TextBox
        Me.Col2TextBox = New System.Windows.Forms.TextBox
        Me.TestBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.WPMlocalDataSet = New TabTestApp.WPMlocalDataSet
        Me.TestTableAdapter = New TabTestApp.WPMlocalDataSetTableAdapters.testTableAdapter
        Me.TableAdapterManager = New TabTestApp.WPMlocalDataSetTableAdapters.TableAdapterManager
        Me.TextBox1 = New System.Windows.Forms.TextBox
        IdxLabel = New System.Windows.Forms.Label
        Col1Label = New System.Windows.Forms.Label
        Col2Label = New System.Windows.Forms.Label
        CType(Me.TestBindingNavigator, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.TestBindingNavigator.SuspendLayout()
        Me.TabControl1.SuspendLayout()
        Me.TabPage1.SuspendLayout()
        Me.TabPage2.SuspendLayout()
        CType(Me.TestBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.WPMlocalDataSet, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'TestBindingNavigator
        '
        Me.TestBindingNavigator.AddNewItem = Me.BindingNavigatorAddNewItem
        Me.TestBindingNavigator.BindingSource = Me.TestBindingSource
        Me.TestBindingNavigator.CountItem = Me.BindingNavigatorCountItem
        Me.TestBindingNavigator.DeleteItem = Me.BindingNavigatorDeleteItem
        Me.TestBindingNavigator.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.BindingNavigatorMoveFirstItem, Me.BindingNavigatorMovePreviousItem, Me.BindingNavigatorSeparator, Me.BindingNavigatorPositionItem, Me.BindingNavigatorCountItem, Me.BindingNavigatorSeparator1, Me.BindingNavigatorMoveNextItem, Me.BindingNavigatorMoveLastItem, Me.BindingNavigatorSeparator2, Me.BindingNavigatorAddNewItem, Me.BindingNavigatorDeleteItem, Me.TestBindingNavigatorSaveItem})
        Me.TestBindingNavigator.Location = New System.Drawing.Point(0, 0)
        Me.TestBindingNavigator.MoveFirstItem = Me.BindingNavigatorMoveFirstItem
        Me.TestBindingNavigator.MoveLastItem = Me.BindingNavigatorMoveLastItem
        Me.TestBindingNavigator.MoveNextItem = Me.BindingNavigatorMoveNextItem
        Me.TestBindingNavigator.MovePreviousItem = Me.BindingNavigatorMovePreviousItem
        Me.TestBindingNavigator.Name = "TestBindingNavigator"
        Me.TestBindingNavigator.PositionItem = Me.BindingNavigatorPositionItem
        Me.TestBindingNavigator.Size = New System.Drawing.Size(752, 25)
        Me.TestBindingNavigator.TabIndex = 1
        Me.TestBindingNavigator.Text = "BindingNavigator1"
        '
        'BindingNavigatorAddNewItem
        '
        Me.BindingNavigatorAddNewItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.BindingNavigatorAddNewItem.Image = CType(resources.GetObject("BindingNavigatorAddNewItem.Image"), System.Drawing.Image)
        Me.BindingNavigatorAddNewItem.Name = "BindingNavigatorAddNewItem"
        Me.BindingNavigatorAddNewItem.RightToLeftAutoMirrorImage = True
        Me.BindingNavigatorAddNewItem.Size = New System.Drawing.Size(23, 22)
        Me.BindingNavigatorAddNewItem.Text = "Add new"
        '
        'BindingNavigatorCountItem
        '
        Me.BindingNavigatorCountItem.Name = "BindingNavigatorCountItem"
        Me.BindingNavigatorCountItem.Size = New System.Drawing.Size(35, 22)
        Me.BindingNavigatorCountItem.Text = "of {0}"
        Me.BindingNavigatorCountItem.ToolTipText = "Total number of items"
        '
        'BindingNavigatorDeleteItem
        '
        Me.BindingNavigatorDeleteItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.BindingNavigatorDeleteItem.Image = CType(resources.GetObject("BindingNavigatorDeleteItem.Image"), System.Drawing.Image)
        Me.BindingNavigatorDeleteItem.Name = "BindingNavigatorDeleteItem"
        Me.BindingNavigatorDeleteItem.RightToLeftAutoMirrorImage = True
        Me.BindingNavigatorDeleteItem.Size = New System.Drawing.Size(23, 22)
        Me.BindingNavigatorDeleteItem.Text = "Delete"
        '
        'BindingNavigatorMoveFirstItem
        '
        Me.BindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.BindingNavigatorMoveFirstItem.Image = CType(resources.GetObject("BindingNavigatorMoveFirstItem.Image"), System.Drawing.Image)
        Me.BindingNavigatorMoveFirstItem.Name = "BindingNavigatorMoveFirstItem"
        Me.BindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = True
        Me.BindingNavigatorMoveFirstItem.Size = New System.Drawing.Size(23, 22)
        Me.BindingNavigatorMoveFirstItem.Text = "Move first"
        '
        'BindingNavigatorMovePreviousItem
        '
        Me.BindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.BindingNavigatorMovePreviousItem.Image = CType(resources.GetObject("BindingNavigatorMovePreviousItem.Image"), System.Drawing.Image)
        Me.BindingNavigatorMovePreviousItem.Name = "BindingNavigatorMovePreviousItem"
        Me.BindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = True
        Me.BindingNavigatorMovePreviousItem.Size = New System.Drawing.Size(23, 22)
        Me.BindingNavigatorMovePreviousItem.Text = "Move previous"
        '
        'BindingNavigatorSeparator
        '
        Me.BindingNavigatorSeparator.Name = "BindingNavigatorSeparator"
        Me.BindingNavigatorSeparator.Size = New System.Drawing.Size(6, 25)
        '
        'BindingNavigatorPositionItem
        '
        Me.BindingNavigatorPositionItem.AccessibleName = "Position"
        Me.BindingNavigatorPositionItem.AutoSize = False
        Me.BindingNavigatorPositionItem.Name = "BindingNavigatorPositionItem"
        Me.BindingNavigatorPositionItem.Size = New System.Drawing.Size(50, 23)
        Me.BindingNavigatorPositionItem.Text = "0"
        Me.BindingNavigatorPositionItem.ToolTipText = "Current position"
        '
        'BindingNavigatorSeparator1
        '
        Me.BindingNavigatorSeparator1.Name = "BindingNavigatorSeparator1"
        Me.BindingNavigatorSeparator1.Size = New System.Drawing.Size(6, 25)
        '
        'BindingNavigatorMoveNextItem
        '
        Me.BindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.BindingNavigatorMoveNextItem.Image = CType(resources.GetObject("BindingNavigatorMoveNextItem.Image"), System.Drawing.Image)
        Me.BindingNavigatorMoveNextItem.Name = "BindingNavigatorMoveNextItem"
        Me.BindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = True
        Me.BindingNavigatorMoveNextItem.Size = New System.Drawing.Size(23, 22)
        Me.BindingNavigatorMoveNextItem.Text = "Move next"
        '
        'BindingNavigatorMoveLastItem
        '
        Me.BindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.BindingNavigatorMoveLastItem.Image = CType(resources.GetObject("BindingNavigatorMoveLastItem.Image"), System.Drawing.Image)
        Me.BindingNavigatorMoveLastItem.Name = "BindingNavigatorMoveLastItem"
        Me.BindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = True
        Me.BindingNavigatorMoveLastItem.Size = New System.Drawing.Size(23, 22)
        Me.BindingNavigatorMoveLastItem.Text = "Move last"
        '
        'BindingNavigatorSeparator2
        '
        Me.BindingNavigatorSeparator2.Name = "BindingNavigatorSeparator2"
        Me.BindingNavigatorSeparator2.Size = New System.Drawing.Size(6, 25)
        '
        'TestBindingNavigatorSaveItem
        '
        Me.TestBindingNavigatorSaveItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
        Me.TestBindingNavigatorSaveItem.Image = CType(resources.GetObject("TestBindingNavigatorSaveItem.Image"), System.Drawing.Image)
        Me.TestBindingNavigatorSaveItem.Name = "TestBindingNavigatorSaveItem"
        Me.TestBindingNavigatorSaveItem.Size = New System.Drawing.Size(23, 22)
        Me.TestBindingNavigatorSaveItem.Text = "Save Data"
        '
        'TabControl1
        '
        Me.TabControl1.Controls.Add(Me.TabPage1)
        Me.TabControl1.Controls.Add(Me.TabPage2)
        Me.TabControl1.Location = New System.Drawing.Point(63, 70)
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(468, 247)
        Me.TabControl1.TabIndex = 2
        '
        'TabPage1
        '
        Me.TabPage1.Controls.Add(Col1Label)
        Me.TabPage1.Controls.Add(Me.Col1TextBox)
        Me.TabPage1.Controls.Add(IdxLabel)
        Me.TabPage1.Controls.Add(Me.IdxTextBox)
        Me.TabPage1.Location = New System.Drawing.Point(4, 22)
        Me.TabPage1.Name = "TabPage1"
        Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
        Me.TabPage1.Size = New System.Drawing.Size(460, 221)
        Me.TabPage1.TabIndex = 0
        Me.TabPage1.Text = "TabPage1"
        Me.TabPage1.UseVisualStyleBackColor = True
        '
        'TabPage2
        '
        Me.TabPage2.Controls.Add(Col2Label)
        Me.TabPage2.Controls.Add(Me.Col2TextBox)
        Me.TabPage2.Location = New System.Drawing.Point(4, 22)
        Me.TabPage2.Name = "TabPage2"
        Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
        Me.TabPage2.Size = New System.Drawing.Size(460, 221)
        Me.TabPage2.TabIndex = 1
        Me.TabPage2.Text = "TabPage2"
        Me.TabPage2.UseVisualStyleBackColor = True
        '
        'IdxLabel
        '
        IdxLabel.AutoSize = True
        IdxLabel.Location = New System.Drawing.Point(146, 54)
        IdxLabel.Name = "IdxLabel"
        IdxLabel.Size = New System.Drawing.Size(23, 13)
        IdxLabel.TabIndex = 0
        IdxLabel.Text = "idx:"
        '
        'IdxTextBox
        '
        Me.IdxTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.TestBindingSource, "idx", True))
        Me.IdxTextBox.Location = New System.Drawing.Point(175, 51)
        Me.IdxTextBox.Name = "IdxTextBox"
        Me.IdxTextBox.Size = New System.Drawing.Size(100, 20)
        Me.IdxTextBox.TabIndex = 1
        '
        'Col1Label
        '
        Col1Label.AutoSize = True
        Col1Label.Location = New System.Drawing.Point(139, 80)
        Col1Label.Name = "Col1Label"
        Col1Label.Size = New System.Drawing.Size(30, 13)
        Col1Label.TabIndex = 2
        Col1Label.Text = "col1:"
        '
        'Col1TextBox
        '
        Me.Col1TextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.TestBindingSource, "col1", True))
        Me.Col1TextBox.Location = New System.Drawing.Point(175, 77)
        Me.Col1TextBox.Name = "Col1TextBox"
        Me.Col1TextBox.Size = New System.Drawing.Size(100, 20)
        Me.Col1TextBox.TabIndex = 3
        '
        'Col2Label
        '
        Col2Label.AutoSize = True
        Col2Label.Location = New System.Drawing.Point(141, 101)
        Col2Label.Name = "Col2Label"
        Col2Label.Size = New System.Drawing.Size(30, 13)
        Col2Label.TabIndex = 0
        Col2Label.Text = "col2:"
        '
        'Col2TextBox
        '
        Me.Col2TextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.TestBindingSource, "col2", True))
        Me.Col2TextBox.Location = New System.Drawing.Point(177, 98)
        Me.Col2TextBox.Name = "Col2TextBox"
        Me.Col2TextBox.Size = New System.Drawing.Size(100, 20)
        Me.Col2TextBox.TabIndex = 1
        '
        'TestBindingSource
        '
        Me.TestBindingSource.DataMember = "test"
        Me.TestBindingSource.DataSource = Me.WPMlocalDataSet
        '
        'WPMlocalDataSet
        '
        Me.WPMlocalDataSet.DataSetName = "WPMlocalDataSet"
        Me.WPMlocalDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'TestTableAdapter
        '
        Me.TestTableAdapter.ClearBeforeFill = True
        '
        'TableAdapterManager
        '
        Me.TableAdapterManager.BackupDataSetBeforeUpdate = False
        Me.TableAdapterManager.testTableAdapter = Me.TestTableAdapter
        Me.TableAdapterManager.UpdateOrder = TabTestApp.WPMlocalDataSetTableAdapters.TableAdapterManager.UpdateOrderOption.InsertUpdateDelete
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(594, 146)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(100, 20)
        Me.TextBox1.TabIndex = 3
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(752, 421)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.TabControl1)
        Me.Controls.Add(Me.TestBindingNavigator)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.TestBindingNavigator, System.ComponentModel.ISupportInitialize).EndInit()
        Me.TestBindingNavigator.ResumeLayout(False)
        Me.TestBindingNavigator.PerformLayout()
        Me.TabControl1.ResumeLayout(False)
        Me.TabPage1.ResumeLayout(False)
        Me.TabPage1.PerformLayout()
        Me.TabPage2.ResumeLayout(False)
        Me.TabPage2.PerformLayout()
        CType(Me.TestBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.WPMlocalDataSet, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()
 
    End Sub
    Friend WithEvents WPMlocalDataSet As TabTestApp.WPMlocalDataSet
    Friend WithEvents TestBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents TestTableAdapter As TabTestApp.WPMlocalDataSetTableAdapters.testTableAdapter
    Friend WithEvents TableAdapterManager As TabTestApp.WPMlocalDataSetTableAdapters.TableAdapterManager
    Friend WithEvents TestBindingNavigator As System.Windows.Forms.BindingNavigator
    Friend WithEvents BindingNavigatorAddNewItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents BindingNavigatorCountItem As System.Windows.Forms.ToolStripLabel
    Friend WithEvents BindingNavigatorDeleteItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents BindingNavigatorMoveFirstItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents BindingNavigatorMovePreviousItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents BindingNavigatorSeparator As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents BindingNavigatorPositionItem As System.Windows.Forms.ToolStripTextBox
    Friend WithEvents BindingNavigatorSeparator1 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents BindingNavigatorMoveNextItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents BindingNavigatorMoveLastItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents BindingNavigatorSeparator2 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents TestBindingNavigatorSaveItem As System.Windows.Forms.ToolStripButton
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
    Friend WithEvents Col1TextBox As System.Windows.Forms.TextBox
    Friend WithEvents IdxTextBox As System.Windows.Forms.TextBox
    Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
    Friend WithEvents Col2TextBox As System.Windows.Forms.TextBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
 
End Class

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-03-12 at 18:34:13ID24226369
Tags

VB.NET

,

Winforms

,

VB.NET 2.0

,

Visual Studio 2008

Topics

.NET

,

Microsoft Visual Basic.Net

,

VB Controls

Participating Experts
2
Points
500
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Forms and TabControl back color
    Hello, I have a Tabcontrol on one of my forms. The form has a background image. I want to make the TabControl invisible or transparent so that the background image from the main form can be seen through the TabControl. The way it is now, the tabs don't take up the whol...
  2. Need help with a databound form and Dataset: Urgent!!
    This has become frustrating and I know It has to be so easy. I have Dataset loaded from a single table on an access back end. I'm using a form with 6 text boxes Name, address, etc. all are databound to fields in the dataset. I used a commandbuilder object and want to upd...
  3. DataSet is derived from the base DataSet class
    Which type of DataSet is derived from the base DataSet class and then uses information in an XML Schema file (.xsd file) in order to generate a new class? My Answer: D) Choice A) Untyped DataSet Choice B) Typed DataSet Choice C) XML DataSet Choice D) XSD DataSet
  4. Detecting when databound textboxes's values have been …
    I have a VB 2005 WinForm application. On it I have a TabControl with 8 TabPages, each one having about 10 TextBoxes databound to a couple of BindingSources (which are bound to a DataSet) I would like to know when the user has changed any values in the TextBoxes so that, befo...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: bd9000Posted on 2009-03-12 at 19:21:35ID: 23875669

I made the following change to the code above to get it to work with iterating through the TabPages (I was trying to set the TextBox.Text on the click event of the navigation controls, originally, but the event firing order of the BindingNavigator throws the records out of synch, so the best way, so far, is to use the TextChanged event of the textbox to make it work, instead)

Public Class Form1
 
    Private Sub TestBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TestBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.WPMlocalDataSet)
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'WPMlocalDataSet.test' table. You can move, or remove it, as needed.
        Me.TestTableAdapter.Fill(Me.WPMlocalDataSet.test)
 
        IterateTabs_TabControl1() 'the textchanged event will fire for the textbox once the iteration hits the TabPage the textbox is on
    End Sub
 
    Private Sub IterateTabs_TabControl1()
        With TabControl1
            Dim lastSelectedTabIndex As Integer = .SelectedIndex
            If lastSelectedTabIndex < 0 OrElse lastSelectedTabIndex > .TabCount Then lastSelectedTabIndex = 0
            For currentTab As Integer = 0 To .TabCount - 1
                .SelectedIndex = currentTab
            Next
            .SelectedIndex = lastSelectedTabIndex
        End With
    End Sub
 
    Private Sub TestBindingNavigator_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TestBindingNavigator.Click
        IterateTabs_TabControl1()
    End Sub
 
    Private Sub BindingNavigatorMoveFirstItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveFirstItem.Click
        IterateTabs_TabControl1()
    End Sub
 
    Private Sub BindingNavigatorMoveLastItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveLastItem.Click
        IterateTabs_TabControl1()
    End Sub
 
    Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
        IterateTabs_TabControl1()
    End Sub
 
    Private Sub BindingNavigatorMovePreviousItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMovePreviousItem.Click
        IterateTabs_TabControl1()
    End Sub
 
    Private Sub Col2TextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Col2TextBox.TextChanged
        Me.TextBox1.Text = Me.Col2TextBox.Text  'the assignment must happen here, not in the MoveNext/Previous/First/Last click events
    End Sub
End Class

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:

Select allOpen in new window

 

by: bd9000Posted on 2009-03-13 at 09:34:56ID: 23881120

Anyone know of a better way to do this?

 

by: DabasPosted on 2009-03-13 at 13:32:46ID: 23883244

I have been able to reproduce your problem and have found a solution too!

The best way is to handle the events of the binding source, as they are not GUI dependant

    Private Sub TestBindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestBindingSource.CurrentChanged
        Dim drv As DataRowView = CType(TestBindingSource.Current, DataRowView)
 
        Me.TextBox1.Text = CType(drv.Row, YourClass.RowObject).FieldName
    End Sub
                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: bd9000Posted on 2009-03-20 at 16:12:54ID: 23944770

That's great, thanks.
I'll just have to make a calculations on the "backside" from here on out.
The flipping through the tabs was a poor solution (I figured it was).

 

by: bd9000Posted on 2009-08-08 at 16:39:25ID: 25052163

I created a better solution for controls residing on other TabPages (for all of those people struggling with this issue):

Here was what I came up with for controls on other tabpages that have yet to be created:
The BindingComplete event for the binding source will fire for each databound control (even ones not created yet), so this was the logical place to start.


 
Private Sub YourBindingSource_BindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.BindingCompleteEventArgs) Handles YourBindingSource.BindingComplete
 
        If Not e.Binding.Control.Created Then
            'if a control is residing on a different tabpage and the tabpage has not yet been selected, the child controls will not be created, hence this test
 
            'make sure the control's parent is a tabpage
            If e.Binding.Control.Parent.GetType.Name.ToLower = "tabpage" Then
 
                'show the tabpage - note the tabControl selectedIndex remains the same
                e.Binding.Control.Parent.Show()
 
                'The child controls on the tab page will now be created and filled with data!
            End If
        End If
 
 
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen in new window

 

by: bd9000Posted on 2009-10-26 at 20:33:34ID: 25668951

oops! That solution does not work either. - the control is not created until the tab page is clicked on by the user, so e.Binding.Control.Created will remain false - still!
Also, setting the " Me.TextBox1.Text = CType(drv.Row, YourClass.RowObject).FieldName"  in the accepted solution above only works for controls on a TabPage that has been viewed already.  Me.TextBox1.Text will never bind, so you can't do control validation (which is the whole point!).  The only solution to provide control validation (ie validate a textbox) is to iterate the tabpages or to remove control validation altogether as a group and validate each control separately on the LostFocus and/or Leave events, then validate the data in the datasource as a group when saving the record, bubble up the events, then create "custom" validators.

It seems every other new "time saving" tool created by MS has turned out to be (once again) utterly worthless for every day use.

 

by: hymie42Posted on 2009-11-25 at 14:09:47ID: 25911618

Brilliant solution - thanks so much for posting :)

 

by: hymie42Posted on 2009-11-25 at 14:12:19ID: 25911633

It worked fo rme as my users are viewing the tabs is what I meant to say.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...