Error in Designer, Data Bindings Not Present.

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Well,

I'm more or less curious to the "why" other than the How to fix, because I've got some of that already.

Basically, my form is riddled with Data Access stuff, but this is a Forms problem. I've added all my BindingSources, and controls that are bound through those binding sources, with the automated creation of the DataSet, TableAdapterManger, etc. (a trifle annoying when i'm doing things a bit differently.)

But that's only the set up not the issue. When you take a Strongly Typed Dataset, that containes Typed DataTables, you can drop them onto the form. Individual Controls or the whole package as "Details" or "Data Grid", and voila it's on the form. In Details mode especially, the form designer Creates all the necessary background components (non-visual) as well as the visual ones (textboxes etc), and automatically handles the DataBinding.

THe BindingSource is set to the Typed DataSet with the Appropriate DataMember selected, and the control is databound (Text Property or whatnot) to the BindingSource and the appropriate column in the DataTable.

But then I delete the Dataset and TableAdapter. I don't need them. I have a full control class that handles ALL of my data transactions, connections, commits/rollbacks, etc in one Class.
As is necessary, though, I went into the "New()" constructor for my form where there is this line:
VB.NET:
      ' This call is required by the Windows Form Designer.
      InitializeComponent()
      ' Add any initialization after the InitializeComponent() call.

So I did. I added all the Initializations for my BindingSources that are on the form -After the InitializeComponent()[/c] call. This is Important to the error now.

So I recently added another control (WebBrowser) and DataBound the DocumentText property to a column in a DataTable and Have set it up pretty much the exact same way I have done every other control/databinding.

(This is the Generated Code from when I FIRST put the controls on the form, and the bindings that Occurred Through Designer Editing, not editing the Designer.vb)
VB.NET:
[u]InitializeComponents[/u]
Me.ContactNameTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.bind_Customers, "ContactName", True))
Me.BOLEmailCmb.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.bind_BOL, "Email", True))
Me.BOL_IDTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.bind_BOL, "BOL_ID", True))
Me.AddrToTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.bind_MailBox, "AddrTo", True))

(This is my Constructor which handles all my databinding sources, as well as ComboBox selection sources)
VB.NET:
   Public Sub New()
      ' This call is required by the Windows Form Designer.
      InitializeComponent()
      Me.Icon = My.Resources.univ
      ' Add any initialization after the InitializeComponent() call.
      BOLQuantityUpDown.Maximum = Integer.MaxValue
      BOLQuantityUpDown.Minimum = -1
      EmailExpQtyUpDown.Maximum = Integer.MaxValue
      EmailExpQtyUpDown.Minimum = -1
      dgv_Child1.AutoGenerateColumns = False
      dgv_Child2.AutoGenerateColumns = False
      dgvTables.AutoGenerateColumns = True
      bind_BOL.DataSource = _RexCon.RexamDS
      bind_BOL.DataMember = "tbl_BOL"
      bind_Customers.DataSource = _RexCon.RexamDS
      bind_Customers.DataMember = "lst_Customers"
      bind_CorbiLoc.DataSource = _RexCon.RexamDS
      bind_CorbiLoc.DataMember = "lst_CorbiLoc"
      bind_Email.DataSource = _RexCon.RexamDS
      bind_Email.DataMember = "tbl_Email"
      bind_Material.DataSource = _RexCon.RexamDS
      bind_Material.DataMember = "lst_Material"
      bind_MailBox.DataSource = _RexCon.RexamDS
      bind_MailBox.DataMember = "tbl_MailBox"
      
      bind_TblList.DataSource = _RexCon.RexamDS
      bind_TblList.DataMember = "qry_Tables"

      bind_Tbls.DataSource = _RexCon.RexamDS
      bind_Tmp.DataSource = _RexCon.RexamDS

      MaterialColCmb.DisplayMember = "Description"
      MaterialColCmb.ValueMember = "Mat_ID"
      CustomerColCmb.DisplayMember = "Name"
      CustomerColCmb.ValueMember = "Cust_ID"
      EmailColCmb.DisplayMember = "Email_ID"
      EmCustomerCol.DisplayMember = "Name"
      EmCustomerCol.ValueMember = "Cust_ID"
      ReturnCodeComboBox.DisplayMember = "ID"
      ReturnCodeComboBox.ValueMember = "ID"
      SQLText.SelectionBackColor = Color.Yellow

      AssociateControlEnter(Me.Controls)
   End Sub

But this is the kicker:
VB.NET:
Me.BodyBrowser.DataBindings.Add(New System.Windows.Forms.Binding("DocumentText", Me.bind_MailBox, "Body", True))
That Line cannot exist in the InitializeComponents() method. When It does, an unhandled exception occurs, claiming that "Body" is not a valid dataMember on dataSource "bind_Mailbox".

Well of course it isn't "valid" yet since the bindingSource itself hasn't been bound, but NONE of them have, so why does this particular binding fail when all the other ones in the application do not fail even though their binding sources haven't been initialized either.

I fixed it for now by moving the binding into the constructor after the bind_Mailbox's datasource was initialized, but in the end, that's like the most random "invent-an-error" i've come across so far. If the dataMember must exist on the bindingSource in order to databind a control to that bindSource & column, then ALL of my databindings should be suspect. However, they all work, so i MUST deduce that it's okay to bind a property to a dataSource and column before the bindSource has been initialized.
Tis all a bit confusing.

Thanks
 

Latest posts

Back
Top