Bart,
I've followed these guidelines in my working application. However there
is an interesting yet serious glitch.
There is a slightly different glitch depending on how the combobox is
configured. The glitches are very specific so I will careful explain
them in separate sections below.
I'll name and describe these like this:
Glitch 1 - Occurs when the comboBox is configured using properties
window and the "ComboBox Tasks" box.
Glitch 2 - Occurs when the comboBox is configured using code only
(except that the control was dragged from the DataSouces window)
See the sections below...
In both cases the forms that hold the comboboxes are contained in
auxiliary forms ('A' and 'B').
The form-use scenario goes like this:
The user configures data for records in the DataGridView by opening one
and then another of these four forms.
I believe the glitches are related even though they appear at different
times in this scenario.
Glitch 1 (properties & generated code) False data is displayed when the
form opens for the first time and displays correctly for all subsequent
times the form is opened.
Glitch 2 (Manual code) The for opens and seems to operate correctly
when it first opens, but always throws an error the second time it is
opened (whether data is changed or not).
Now for greater description and code.
=====================================================
Glitch 1 - Occurs when the comboBox is configured using properties
window and the "ComboBox Tasks" box.
-----------------------------------------------------
Behavior:
· This behavior happens on a session basis, not on a record basis.
· The first time form 'A' is opened you cannot trust what you see in
the comboBox. The comboBox will *always* display data.
· However every subsequent time form 'A' is opened in the same
session (no mater if it is the same record or a completely different
record, you can *always* trust what the comboBox displays.
Form 'B' same as form 'A'
· When the user opens form 'B' for the first time you cannot trust
what you see in the comboBox. The comboBox will *always* display data.
· And every subsequent time form 'B' is opened in the same session
you can *always* trust what the comboBox displays.
Summary of Glitch 1:
· The first time a form is opened in a session the combox will
*always* be Untrustworthy.
· The second time (and thereafter) a form is opened in a session the
combobox will *always* be Trustworthy.
Here is the code that opens the form (same for glitch 1 and 2):
\\\
Protected Sub btnMachineInfo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnMachineInfo.Click
' Indicate the mode used to open this form so the certain
buttons can be disabled and others enabled
bFormOpenedDirectly = True
' Populate the values to be used in the opening form as
parameters in tableAdapter FillBy statement
GetQuoteIdVersionId()
Dim f As Form = MachineInformation
Me.Visible = False
' Open as dialog so that the bFormOpenedDirecly can be
cleared after returning
f.ShowDialog()
Me.Visible = True
bFormOpenedDirectly = False
End Sub
///
Here is the code in the opening forms load method in Glitch 1 scenario:
\\\
Private Sub MachineVersion_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
' Change Text of inherited label
Me.lblFormTitle.Text = "Machine Information"
' Enable buttons based on how the form is opened
Me.btnNext.Enabled = Not QuotesOverview.bFormOpenedDirectly
Me.btnPrevious.Enabled = Not QuotesOverview.bFormOpenedDirectly
Me.btnSave.Enabled = QuotesOverview.bFormOpenedDirectly
'Me.btnCancel.Visible = False
' Fill TableAdapters
Me.Tbl010QuoteTableAdapter.FillByQuoteId(DataSet1.tbl010Quote,
QuotesOverview.quoteId)
Me.Tbl020VersionTableAdapter.FillByQuoteAndVersion(DataSet1.tbl020Version,
QuotesOverview.quoteId, QuotesOverview.versionId)
Me.Tbl050OptionTableAdapter.Fill(Me.DataSet1.tbl050Option)
' Get and display the Quote Number formatted the way users
expect to see it
CurrentQuoteIdLabel.Text = QuotesOverview.GetIAQuoteNumber
End Sub
///
Here is pertinent comboBox code from Designer generated code within
MachineIformation.Desiger.vb:
\\\
'Op1QuantityofNestsComboBox
'
Me.Op1QuantityofNestsComboBox.DataBindings.Add(New
System.Windows.Forms.Binding("SelectedValue",
Me.Tbl020VersionBindingSource, "op1QuantityofNests", True))
Me.Op1QuantityofNestsComboBox.DataSource =
Me.QuanNestsBindingSource
Me.Op1QuantityofNestsComboBox.DisplayMember = "OptionText"
Me.Op1QuantityofNestsComboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.Op1QuantityofNestsComboBox.FormattingEnabled = True
Me.Op1QuantityofNestsComboBox.Location = New
System.Drawing.Point(114, 344)
Me.Op1QuantityofNestsComboBox.Name =
"Op1QuantityofNestsComboBox"
Me.Op1QuantityofNestsComboBox.Size = New
System.Drawing.Size(121, 21)
Me.Op1QuantityofNestsComboBox.TabIndex = 34
Me.Op1QuantityofNestsComboBox.ValueMember = "pkOptionId"
///
=== End of the Glitch 1 description =====================
=====================================================
Glitch 2 - Occurs when the comboBox is configured using code only
(except that the control was dragged from the DataSouces window)
-----------------------------------------------------
Behavior:
· This behavior cannot be associated with session or record because
it results in an error.
· The first time form 'A' is opened the comboBox displays properly
and as expected. The comboBox is empty if the field is empty. The
comboBox show the appropriate values if the values have been saved to
that field.
· However when you try to open form 'A' the second time an error is
thrown.
Form 'B' has the same behavior as form 'A'
The code to open the form is the same for both glitch scenarios:
Here is the code in the opening form load method in Glitch 2 scenario:
\\\
Private Sub MachineVersion_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
' Change Text of inherited label
Me.lblFormTitle.Text = "Machine Information"
' Enable buttons based on how the form is opened
Me.btnNext.Enabled = Not QuotesOverview.bFormOpenedDirectly
Me.btnPrevious.Enabled = Not QuotesOverview.bFormOpenedDirectly
Me.btnSave.Enabled = QuotesOverview.bFormOpenedDirectly
'Me.btnCancel.Visible = False
' Fill TableAdapters
Me.Tbl010QuoteTableAdapter.FillByQuoteId(DataSet1.tbl010Quote,
QuotesOverview.quoteId)
Me.Tbl020VersionTableAdapter.FillByQuoteAndVersion(DataSet1.tbl020Version,
QuotesOverview.quoteId, QuotesOverview.versionId)
Me.Tbl050OptionTableAdapter.Fill(Me.DataSet1.tbl050Option)
' Get and display the Quote Number formatted the way users
expect to see it
CurrentQuoteIdLabel.Text = QuotesOverview.GetIAQuoteNumber
'The following code is unique to Glitch 2 because it is manually
written.
' PartSize Combobox
Me.Op1PartSizeComboBox.DataSource = Me.PartSizeBindingSource
Me.Op1PartSizeComboBox.DisplayMember = "OptionText"
Me.Op1PartSizeComboBox.ValueMember = "pkOptionId"
Me.Op1PartSizeComboBox.FormattingEnabled = True
' bind lookup to master
' <<< The line below throws the error when the form is opened the
second time. >>>
Me.Op1PartSizeComboBox.DataBindings.Add("SelectedValue",
Me.Tbl020VersionBindingSource, "op1PartSize")
End Sub
///
Here is pertinent comboBox code from Designer generated code within
MachineIformation.Desiger.vb:
\\\
'Op1PartSizeComboBox
'
Me.Op1PartSizeComboBox.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.Op1PartSizeComboBox.FormattingEnabled = True
Me.Op1PartSizeComboBox.Location = New System.Drawing.Point(114,
317)
Me.Op1PartSizeComboBox.Name = "Op1PartSizeComboBox"
Me.Op1PartSizeComboBox.Size = New System.Drawing.Size(121, 21)
Me.Op1PartSizeComboBox.TabIndex = 33
///
Here is the error message
\\\
System.ArgumentException was unhandled
Message="This causes two bindings in the collection to bind to the
same property.
Parameter name: binding"
ParamName="binding"
Source="System.Windows.Forms"
StackTrace:
at
System.Windows.Forms.ControlBindingsCollection.CheckDuplicates(Binding
binding)
at System.Windows.Forms.Binding.CheckBinding()
at
System.Windows.Forms.Binding.SetBindableComponent(IBindableComponent
value)
at
System.Windows.Forms.ControlBindingsCollection.AddCore(Binding
dataBinding)
at System.Windows.Forms.ControlBindingsCollection.Add(String
propertyName, Object dataSource, String dataMember, Boolean
formattingEnabled, DataSourceUpdateMode updateMode, Object nullValue,
String formatString, IFormatProvider formatInfo)
at System.Windows.Forms.ControlBindingsCollection.Add(String
propertyName, Object dataSource, String dataMember)
at
QmsUserInterface.MachineInformation.MachineVersion_Load(Object sender,
EventArgs e) in D:\DBuchanan MyDocuments\IA\Dev Projects\QMS I\AppDev -
QMS\QMS_01 2006-01-30\QmsUI\Forms_Derived01\MachineInformation.vb:line
43
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at QmsUserInterface.QuotesOverview.btnMachineInfo_Click(Object
sender, EventArgs e) in D:\DBuchanan MyDocuments\IA\Dev Projects\QMS
I\AppDev - QMS\QMS_01
2006-01-30\QmsUI\Forms_Derived01\QuotesOverview.vb:line 210
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)
at QmsUserInterface.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
///
=== End of the Glitch 2 description =====================
What could be causing these behaviors?
What are the remedies in each scenario?
Thank you,
dbuchanan