Terry Rueter

(Beta 2)

I get an error message, "DataMember property 'AccountingPeriodId' cannot be found on the DataSource." when calling the Find method on my binding source:

AccountingPeriodBindingSource.Find("AccountingPeriodId", 7);

Any clues

TIA,
Rob



Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Tony Maynard-Smith

 RobLinton wrote:

(Beta 2)

I get an error message, "DataMember property 'AccountingPeriodId' cannot be found on the DataSource." when calling the Find method on my binding source:

AccountingPeriodBindingSource.Find("AccountingPeriodId", 7);

Any clues

TIA,
Rob



I get the same error on the released version of VB 2005 Express.  I can use the BindingSource to do other things such as:

FootpathsBindingSource.Position = i

and

FootpathsBindingSource.SupportsSearching()

returns "true", but I can't see how to get .Find to work.

Thanks, Tony.





Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Daniel Herling Microsoft

Assuming that your BindingSource is bound to a DataTable/DataView, then for BindingSource::Find property the string parameter is the name of the column, while the object parameter is the key. The return value is the index of the match for the Find request.


Here is some code that displays this:

DataTable tbl = new DataTable();

tbl.Columns.Add("ID", typeof(int));

tbl.Rows.Add(1);

tbl.Rows.Add(2);

tbl.Rows.Add(10);

BindingSource b = new BindingSource();

b.DataSource = tbl;

if (b.Find("ID", 1) >= 0)

{

Console.WriteLine("Found!!");

}

else

{

Console.WriteLine("NOT Found!!");

}


The output from this code is:

Found!!

Hope this helps.

Daniel.






Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Tony Maynard-Smith

I am afraid your code won't run under VB 2005 Express, so in itself was not much use.

I have got BindingSource.Find() to work OK and as expected when the BindingSource is bound directly to a Table in a  Dataset (connected to a database in SQL Server Express).  My problem comes when I have two related Tables, and try to use Find() on a BindingSource which is bound to a second BindingSource (with DataMember as a Relation), which is then bound to a Table in a Dataset.

I can use Position() to move the current position in a "second level" related BindingSource as described above, and as I said earlier SupportsSearching() returns "true", but I can't work out the format for the property parameter of Find().   Is there a way of doing this

(I can get the same effect by writing my own Do-loop to do a linear search, but it is not very elegant.)

With thanks, Tony.




Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Terry Rueter

I am having the same exact problem.  I have spent a couple of hours on it with no luck.



Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Terry Rueter

The BindingSource.Find method seems to work ony on the master BindingSource in a master details configuration.  In my case; master is an "Exam" table and details is a "Question" table.  The BindingSource for Exam is "BindingSource0" and for Question it is "BindingSource1".  The data is in a SQL 2005 database and the relationship is defined.  QuestionID is a primary key field in the Question table.


When attempting to use BindingSource.Find ("QuestionID", SearchKey), I get the followinng error:  "DataMember property 'QuestionID' cannot be found on the DataSource." 

I noticed the DataMember property for BindingSource1 is "FK_Question_Exam" and the DataSource property is BindingSource0.  This must be what makes the relational aspect work.

I have seen one other post on the forum describing the same problem, but there was no resolution. 




Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

CM De Vries

I have the exact problem ...

the Find method works fine on the Master Binding source but not on the Child bindingsource.




Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Terry Rueter

I finally contacted Microsoft Technical Support and registered an incident for this.  After 4 hours on the phone with the tech remote controlling my system we found the resolution to this problem. 

When you drag an item from the child table to a form, it automatically creates the BindingSource.  When it does this, it sets the DataSource property for the BindingSource to the wrong value.  All you have to do is select the FKbindingsourcename from the list of available DataSource values for the property. 

This creates yet another BindingSource Control on your form.

 

Here is some furhter background on the solution:

The example I used with the Microsoft tech was a single form, with the SQL Server Northwind sample database connected.  I used the Orders and Order_Details tables as the parent and child respectively.  I dragged the Orders and Order_Details tables to the form to create the DataGridView controls.  Originally, the relational mechanism worked properly except for the BindingSource.Find method on the Order_DetailsBindingSource.

The parent BindingSource was OrdersBindingSource.  The child BindingSource was Order_DetailsBindingSource.  The only thing that has to be changed to fix the Find mentod is to change the DataSource property on the Order_DetailsBindingSource to FKOrderDetailsOrdersBindingSource.  Doing this resulted in the FKOrderDetailsOrdersBindingSource control being added to the form. 

 





Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

ajstadlin2

That worked for me!  Thanks!



Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Tom Leeson

This cured my problems with a master detail setup!! Wasted two days doing loads of stuff All cool now



Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

CoolData

When you want to Find a row on a related BindingSource you should use the overload that takes the PropertyDescriptor.

PropertyDescriptorCollection pdc = currentBindingSource.CurrencyManager.GetItemProperties();

int pos = currentBindingSource.Find(pdc["QuestionID"], SearchKey);

if (pos >= 0) currentBindingSource.Position = pos;

Enjoy!






Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Good-man

This thread's "Accepted Answer" was not helpful because it cause some side effects that I wasn't willing to work around.

 But using the PropertyDescriptorCollection worked perfectly!  Thanks!

 

 






Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

LucMorin

I've been through the same hoops myself, and after reading Terry Reuter's post (Describing a phone call with MS tech support), I'm still left with questions as to the rationale behind having yet another BindingSource object created.

Is there anyone on this forum with enough background information to explain this behavior I find that when I clearly understand the rationale behind a "work around", I'm less scared of using it.

Thank you.





Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Nigel Stratton

Thank you, thank you, thank you!!!

At 3AM on a major project even MS support is not available. This is exactly what I needed to get going again. You are a life saver, thanks for taking the time to log this problem.





Re: Windows Forms Data Controls and Databinding Problem with BindingSource.Find on Relational BindingSource

Alexander Yarushin

Guys,

Indeed, the solution with using overloaded BindingSource.Find Method (PropertyDescriptor, Object) helped.

THANK YOU!

Alexander.