Groups | Blog | Home
all groups > dotnet windows forms databinding > july 2006 >

dotnet windows forms databinding : System.MissingMethodException: Constructor on IBindingList NOT FOU


JT
7/31/2006 8:40:02 AM
Hi all,
I have two datagridviews representing a parent and a child table. If the
user clicks on an empty row's cell in the child datagridview without there
being an owning parent datarow, the above exception is thrown, which makes
sense.
My question, where and how can I intercept this exception, and more
importantly, how can I best prevent it? I would imagine it must involve
changing the setting of AllowNew on the binding source depending on whether a
parent datarow exists, but I am not sure how to do this dynamically?
Thanks.
--
v-lliu NO[at]SPAM online.microsoft.com
8/1/2006 2:16:22 AM
Hi John,

I am sorry that I may not understand your problem fully.

[quoted text, click to view]
without there being an owning parent datarow, the above exception is
thrown, which makes sense.

Could you tell me what you mean in the above sentence?

I have performed a test representing a parent and a child table in two
DataGridViews. When I click on the new row's cell in the child
DataGridView, nothing happens.

Below is the steps of my test.

1. Set up a Windows application.

2. Create a DataSet and add two DataTable in it(e.g ParentTable and
ChildTable). Create a relation between the two DataTables in DataSet
designer(e.g Parent_Child).

3. Drag&drop two DataGridViews and two BindingSource onto the form. Add an
instance of DataSet to the form.(e.g parentDataGridView, childDataGridView,
parentBinding, childBinding, dataset1)

4. Set parentBinding.DataSource = dataset1,
parentBinding.DataMember = "ParentTable",
childBinding.DataSource = parentBinding,
childBinding.DataMember = "Parent_Child",
parentDataGridView.DataSource = parentBinding,
childDataGridView.DataSource = childBinding

When the program is running, the parentDataGridView represents all the data
in the parent table and the childDataGridView represents the corresponding
data in the child table.

Are the steps of my test the same to yours? If not, you may explain in
detail or provide the sample code.

I look forward to your reply.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
JT
8/2/2006 10:05:01 PM
Hi Linda,

My setup steps were a bit different, but arrive at the same binding
configuration. I dragged the parent table to an empty form from the project
datasources window. This created a datagridview, binding source, and binding
navigator ( I deleted the navigator). I then clicked on the + sign on the
parent table in the datasource window treeview, and dragged the child table
from the datasource window to the form. This setup a datagridview for the
child, which had a datasource of the parentBindingSource, and a datamember of
the relationship name. My datasource is a remote dataset object contained in
another project in the same solution.

I then changed the AllowNew property of the childBinding Source to TRUE.

When I run the app, and there is no data in the parent table, clicking on a
row in the child datagridview throws the exception I noted.

Right now, I am working around this by manipulating the
childBindingSource.AllowNew property. I test for parentTable.Rows.Count > 0
OnFormLoad. If the count is 0, I set AllowNew = False, else True. I then
reset the childBindingSource.AllowNew property based on the results of a
cellParsing event in the parent datagridview. This solution seems to be
working.

Any thoughts on a better way to do this, or is this OK?

Thanks.
--
John


[quoted text, click to view]
v-lliu NO[at]SPAM online.microsoft.com
8/3/2006 10:29:02 AM
Hi John,

Thank you for your detailed feedback.

I performed a test based on your description and did reproduce the problem.
I set the childBindingSouce's AllowNew property to true. When the program
is running and there's no data in the parentBindingSource, an error occurs
saying that "Constructor on type 'System.ComponentModel.IBindingList' not
found."

The following is the detailed error message.

System.MissingMethodException: Constructor on type
'System.ComponentModel.IBindingList' not found.
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at System.SecurityUtils.SecureCreateInstance(Type type, Object[] args)
at System.ComponentModel.BindingList`1.AddNewCore()
at
System.ComponentModel.BindingList`1.System.ComponentModel.IBindingList.AddNe
w()
at System.Windows.Forms.BindingSource.AddNew()
at System.Windows.Forms.CurrencyManager.AddNew()
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded(
)
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow, Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at
System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection,
Boolean forceCurrentCellSelection)
at
System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean
includeNewRow)
at System.Windows.Forms.DataGridView.OnEnter(EventArgs e)
at System.Windows.Forms.Control.NotifyEnter()
at System.Windows.Forms.ContainerControl.UpdateFocusedControl()

From the above message, we could see that
System.ComponentModel.IBindingList.AddNew method is called internally when
the BindingSource.AllowNew property has been set to true. Then the program
tries to find the corresponding parent row in the parentBindingSource.
However, in this case, there's no corresponding parent row, so the error
occurs.

I think your workaround is good. I haven't though out a better one.


Sincerely,
Linda Liu
Microsoft Online Community Support

JT
8/3/2006 10:40:01 PM
Once again Linda, thanks for your superb insight and support.
--
John


[quoted text, click to view]
Piotr Jaworski
2/14/2007 12:37:34 AM
Hi.

It could be useful to check if underlying list supports adding.
There may some differences occur between underlying list and binding source, even if You set bindingSource.AllowNew property is set to True.
I had the same problem as You, (the same exception) and simply checking of it solved my problem:

if (this.bindingSourceMySampleSource.Current == null &&
((System.ComponentModel.IBindingList)this.bindingSourceMySampleSource.List).AllowNew
)
{
object obj = this.bindingSourceMySampleSource.AddNew();
}

From http://www.developmentnow.com/g/31_2006_7_0_0_796894/System-MissingMethodException-Constructor-on-IBindingList-NOT-FOU.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button