How to bind property to control (through this[string])
-
Hi all Is exists a way to bind property to control through (this[string]) Ex:
protected override void OnLoad(EventArgs e) { base.OnLoad(e); DataSrc ds = new DataSrc(); this.DataBindings.Add("Text", ds, "Prop1");//no problem } ... ... ... public class DataSrc { public object Prop1 { get { return "Prop1"; } } }
But i realy need to bind control not throug explicit defined property (in case above Prop1) but through this[string PropName] property Ex:protected override void OnLoad(EventArgs e) { base.OnLoad(e); DataSrc ds = new DataSrc(); this.DataBindings.Add("Text", ds, "Prop1");//can't bind!!!! } ... ... ... public class DataSrc { public object this[string PropName] { get { switch(PropName) { ... case "Prop1": return "Prop1"; } } } }
Is exists way to do such way???? THANK -
Hi all Is exists a way to bind property to control through (this[string]) Ex:
protected override void OnLoad(EventArgs e) { base.OnLoad(e); DataSrc ds = new DataSrc(); this.DataBindings.Add("Text", ds, "Prop1");//no problem } ... ... ... public class DataSrc { public object Prop1 { get { return "Prop1"; } } }
But i realy need to bind control not throug explicit defined property (in case above Prop1) but through this[string PropName] property Ex:protected override void OnLoad(EventArgs e) { base.OnLoad(e); DataSrc ds = new DataSrc(); this.DataBindings.Add("Text", ds, "Prop1");//can't bind!!!! } ... ... ... public class DataSrc { public object this[string PropName] { get { switch(PropName) { ... case "Prop1": return "Prop1"; } } } }
Is exists way to do such way???? THANK -
How would you define the PropName? Isn't the whole point of "Prop1" in this.DataBindings.Add("Text", ds, "Prop1") is to let you define in string which property that you want to bind to?
Obviously i was not very clear. this.DataBindings.Add("Text", ds, "Prop1") - for my purpose "Prop1" - should be not property name, but parameter what should pass to
this[string PropName] method. The same way as this act when datat source object is DataRow.
-
Obviously i was not very clear. this.DataBindings.Add("Text", ds, "Prop1") - for my purpose "Prop1" - should be not property name, but parameter what should pass to
this[string PropName] method. The same way as this act when datat source object is DataRow.
-
You were very clear, obviously I was not very clear. :laugh: You can't just take an indexer and use it as property because they look roughly the same. If you really really want to do that, you probably should create a property for each of the indexer.
-you probably should create a property for each of the indexer Good News Evryone (c) futurama It's realy hard when you have about 50 fields. Probably had to implement this throught DataRow class.
-
-you probably should create a property for each of the indexer Good News Evryone (c) futurama It's realy hard when you have about 50 fields. Probably had to implement this throught DataRow class.
-
ORM code generator, map the fields in datarows into data objects. :) BTW, if you map them to data objects, remember to implement OnPropertyChanged or OnXXXXXXChange, or the updating won't be bi-directional.
modified on Friday, May 23, 2008 7:38 AM
ORM code generator - what is this??? Actualy for my objective realy convient to use indexer, since all this invokation i suppose to delegate for internal object what also have same indexer.
public System.Drawing.Color MyStubObject::Indexer[string FieldName]
{
if (ContainedDataRow[FieldName, Original] != ContainedDataRow[FieldName])
{
return System.Drawing.Color.LightGreen;
}
else
{
return System.Drawing.Color.White;
}}
....
control1.DataBindings.Add("EditValue", dataRow, "CLIENT"); control1.DataBindings.Add("BackColor", dataRow.stubObject, "CLIENT"); control2.DataBindings.Add("EditValue", dataRow, "ACCOUNT"); control2.DataBindings.Add("BackColor", dataRow.stubObject, "ACCOUNT");
This way i have all modifyed fields on form with lighted beckground.:cool:
-
ORM code generator - what is this??? Actualy for my objective realy convient to use indexer, since all this invokation i suppose to delegate for internal object what also have same indexer.
public System.Drawing.Color MyStubObject::Indexer[string FieldName]
{
if (ContainedDataRow[FieldName, Original] != ContainedDataRow[FieldName])
{
return System.Drawing.Color.LightGreen;
}
else
{
return System.Drawing.Color.White;
}}
....
control1.DataBindings.Add("EditValue", dataRow, "CLIENT"); control1.DataBindings.Add("BackColor", dataRow.stubObject, "CLIENT"); control2.DataBindings.Add("EditValue", dataRow, "ACCOUNT"); control2.DataBindings.Add("BackColor", dataRow.stubObject, "ACCOUNT");
This way i have all modifyed fields on form with lighted beckground.:cool: