PC Review


Reply
Thread Tools Rate Thread

Conditions of DataBinding

 
 
Martin
Guest
Posts: n/a
 
      27th Nov 2005
what are the conditions in order to bind to an object? i have an object,
which implements the IList interface. Now I'am able to bind the objects,
which are hold by the collection.

now i implemented two properties in my collection. but i'm not able to bind
to the properties of the collection itself. it must be the object in the
list. that are my experiences.

Example:

public class MyCollection : IList {

//Implementations of IList and so on..

public event EventHandler myValueChanged;

public int myValue
{
get { return iMyValue; }
set
{
iMyValue = value;

if(myValueChanged != null)
myValueChanged(this, EventArgs.Empty);
}
}
}

And i try to bind to an object..

//That works...
textBox1.DataBindings.Add("Text", myClassInstance[1],
"ValueOfMyObjectInList");

//That doesn't work
numericBox1.DataBindings.Add("Value", myClassInstance, "myValue");

I get an error which tells me, that he isn't able to bind to a property or
column of the datasource.
parameter name: dataMember

is it possible to bind to a property of a collection itself?


 
Reply With Quote
 
 
 
 
Bart Mermuys
Guest
Posts: n/a
 
      27th Nov 2005
Hi,

"Martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> what are the conditions in order to bind to an object? i have an object,
> which implements the IList interface. Now I'am able to bind the objects,
> which are hold by the collection.
>
> now i implemented two properties in my collection. but i'm not able to
> bind to the properties of the collection itself. it must be the object in
> the list. that are my experiences.
>
> Example:
>
> public class MyCollection : IList {
>
> //Implementations of IList and so on..
>
> public event EventHandler myValueChanged;
>
> public int myValue
> {
> get { return iMyValue; }
> set
> {
> iMyValue = value;
>
> if(myValueChanged != null)
> myValueChanged(this, EventArgs.Empty);
> }
> }
> }
>
> And i try to bind to an object..
>
> //That works...
> textBox1.DataBindings.Add("Text", myClassInstance[1],
> "ValueOfMyObjectInList");
>
> //That doesn't work
> numericBox1.DataBindings.Add("Value", myClassInstance, "myValue");
>
> I get an error which tells me, that he isn't able to bind to a property or
> column of the datasource.
> parameter name: dataMember
>
> is it possible to bind to a property of a collection itself?


No. The fields come from the property on the items, but so does the
values. If you databind a list then there is a CurrencyManager that
maintaince the current position and current values.

You could put your properties outside of the collection into another class
together with an instance of the custom collection.

public class MyComplexObject
{
private int iMyValue;
private MyCollection myCollection = new MyCollection();

// collection property
public MyCollection Collection
{
get { return myCollection(); }
}

// properties on the same level as the collection
// if necesairy these properties could access MyCollection
public event EventHandler myValueChanged;
public int myValue
{
get { return iMyValue; }
set
{
iMyValue = value;
if(myValueChanged != null)
myValueChanged(this, EventArgs.Empty);
}
}
}

public class MyCustomCollection : BindingList<MyCustomObject>
{
// regular typed methods
}

public class MyCustomObject
{
// item properties
}

Then you can bind like:
MyComplexObject myObj = new MyComplexObject();
TextBox.DataBindings.Add("Text", myObj, "myValue" );
DataGrid.DataSource = myObj;
DataGrid.DataMember = "Collection";


HTH,
Greetings

>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Countif Conditions - Use of conditions that vary by cell value JonTarg Microsoft Excel Misc 1 30th May 2008 01:21 PM
Databinding expressions are only supported on objects that have a DataBinding event jobs Microsoft ASP .NET 0 26th Sep 2007 12:54 AM
2 Conditions + Sum of a colum matching those conditions =?Utf-8?B?SmVmZmE=?= Microsoft Excel Worksheet Functions 5 8th Jun 2007 12:14 AM
shade cells based on conditions - i have more than 3 conditions =?Utf-8?B?TW8y?= Microsoft Excel Worksheet Functions 3 30th Mar 2007 07:19 AM
Databinding Bible (REPOST FROM m.p.d.f.WindowsForms.Databinding) a Microsoft ADO .NET 1 16th Jul 2004 03:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:03 PM.