Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to bind property to control (through this[string])

How to bind property to control (through this[string])

Scheduled Pinned Locked Moved C#
helptutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ElCachubrey
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • E ElCachubrey

      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

      D Offline
      D Offline
      darkelv
      wrote on last edited by
      #2

      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?

      E 1 Reply Last reply
      0
      • D darkelv

        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?

        E Offline
        E Offline
        ElCachubrey
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • E ElCachubrey

          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.

          D Offline
          D Offline
          darkelv
          wrote on last edited by
          #4

          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.

          E 1 Reply Last reply
          0
          • D darkelv

            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.

            E Offline
            E Offline
            ElCachubrey
            wrote on last edited by
            #5

            -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.

            D 1 Reply Last reply
            0
            • E ElCachubrey

              -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.

              D Offline
              D Offline
              darkelv
              wrote on last edited by
              #6

              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

              E 1 Reply Last reply
              0
              • D darkelv

                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

                E Offline
                E Offline
                ElCachubrey
                wrote on last edited by
                #7

                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:

                D 1 Reply Last reply
                0
                • E ElCachubrey

                  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:

                  D Offline
                  D Offline
                  darkelv
                  wrote on last edited by
                  #8

                  ORM Wiki[^] Basically you will be working on an object that is mapped to your data, instead of working on datatable, datarow, datacolumn, etc. You may want to look at whether you can write your own DataBinding for binding to the columns of datarow, good luck. ;)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups