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. Bindable Custom Control

Bindable Custom Control

Scheduled Pinned Locked Moved C#
question
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.
  • H Offline
    H Offline
    Hubert
    wrote on last edited by
    #1

    Hi! What should I do to create working bindable property in my custom control? I took System.Windows.Forms.Label, inherited into nLabel (numeric label) and added following code: [Bindable(true)] public int val { get { return _val;} set { _val=value; this.Text=_val.ToString(); } } next I've bound this control and some other control to one datasource. I tried to change value, but value is locked by my control. What is wrong? h.

    I 1 Reply Last reply
    0
    • H Hubert

      Hi! What should I do to create working bindable property in my custom control? I took System.Windows.Forms.Label, inherited into nLabel (numeric label) and added following code: [Bindable(true)] public int val { get { return _val;} set { _val=value; this.Text=_val.ToString(); } } next I've bound this control and some other control to one datasource. I tried to change value, but value is locked by my control. What is wrong? h.

      I Offline
      I Offline
      Ista
      wrote on last edited by
      #2

      try return this.Text; I'm not an expert yet, but I play one at work. Yeah and here too.

      H 1 Reply Last reply
      0
      • I Ista

        try return this.Text; I'm not an expert yet, but I play one at work. Yeah and here too.

        H Offline
        H Offline
        Hubert
        wrote on last edited by
        #3

        I'tried this one - it doesn't work :o( There is really interesting event flow in the bound property. When you try to change value at bound column, property events are fired as following: GET ( :confused: ), SET, SET. First GET destroy any data changes - because it reads from internal data of my class. This makes value "uneditable". How to detect, that data was changed externally or is it possible to not return anything from the property? h.

        I 1 Reply Last reply
        0
        • H Hubert

          I'tried this one - it doesn't work :o( There is really interesting event flow in the bound property. When you try to change value at bound column, property events are fired as following: GET ( :confused: ), SET, SET. First GET destroy any data changes - because it reads from internal data of my class. This makes value "uneditable". How to detect, that data was changed externally or is it possible to not return anything from the property? h.

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          Well it gets every second. I include a blank set set {} and this suffices for my read only One way you might look into is MyClassList : CollectionBase, IBindingList MyClass : IEditableObject Use the customer example in the IEditableObject example in msdn help within the IDE The reason its doing this is it has to raise events notifying the control of changes. I'm not an expert yet, but I play one at work. Yeah and here too.

          H 1 Reply Last reply
          0
          • I Ista

            Well it gets every second. I include a blank set set {} and this suffices for my read only One way you might look into is MyClassList : CollectionBase, IBindingList MyClass : IEditableObject Use the customer example in the IEditableObject example in msdn help within the IDE The reason its doing this is it has to raise events notifying the control of changes. I'm not an expert yet, but I play one at work. Yeah and here too.

            H Offline
            H Offline
            Hubert
            wrote on last edited by
            #5

            HI! thanks for your time and help. I tried to implement IEditableObject in my class, but these methods are not used in regular databinding. They are used in grids only. but the most important I've found the bug: I've made form with datagrid and nLabel connected to one datasource. I found, that they cannot be based on one currency manager. When they are on separate cm, everything works well. I've never seen similar behavior before this one. Could anybody explain it to me? h.

            I 1 Reply Last reply
            0
            • H Hubert

              HI! thanks for your time and help. I tried to implement IEditableObject in my class, but these methods are not used in regular databinding. They are used in grids only. but the most important I've found the bug: I've made form with datagrid and nLabel connected to one datasource. I found, that they cannot be based on one currency manager. When they are on separate cm, everything works well. I've never seen similar behavior before this one. Could anybody explain it to me? h.

              I Offline
              I Offline
              Ista
              wrote on last edited by
              #6

              yes they are used in datagrid or any control that uses an IBindingList I use them for labels also basically my class looks like public class MyClass { private string s; private MyObject i; public string MyString { get { return s; } set { s = value; } } public MyObject ThisObject { get { return i; } set { i = value; } } } public class MyObject { public override string ToString() { return "MyObject class"; } } if any other problems, explain a little more and I can send a prototype project to ya. I had to go trhough hell with getting my databinding to work. My classes wrap the database then bind to classes. And i perform biz rules on them so almost no code in GUI. nick I'm not an expert yet, but I play one at work. Yeah and here too.

              H 1 Reply Last reply
              0
              • I Ista

                yes they are used in datagrid or any control that uses an IBindingList I use them for labels also basically my class looks like public class MyClass { private string s; private MyObject i; public string MyString { get { return s; } set { s = value; } } public MyObject ThisObject { get { return i; } set { i = value; } } } public class MyObject { public override string ToString() { return "MyObject class"; } } if any other problems, explain a little more and I can send a prototype project to ya. I had to go trhough hell with getting my databinding to work. My classes wrap the database then bind to classes. And i perform biz rules on them so almost no code in GUI. nick I'm not an expert yet, but I play one at work. Yeah and here too.

                H Offline
                H Offline
                Hubert
                wrote on last edited by
                #7

                Hi! It seems you truly are an expert - esp. in Windows controls :o) I have just one more question: How the bound property notifies datasource, that it's value has changed? Let's imagine textbox with similar property val as in the numLabel described in my first mail. When value in datasource changes, text in textbox will change. But when user changes text in textBox, datasource doesn't change untill some other control does not refresh data. I played with control bound to dataset and datagrid which shows data from table. When I've changed value in the control, datagrid doesn't show any changes. But when I clicked on bound column in current row of datagrid, the value was read from the control. I'd like to know if there is a way to make it without clicking in datagrid - just like all MS controls do? thanks again h.

                I 1 Reply Last reply
                0
                • H Hubert

                  Hi! It seems you truly are an expert - esp. in Windows controls :o) I have just one more question: How the bound property notifies datasource, that it's value has changed? Let's imagine textbox with similar property val as in the numLabel described in my first mail. When value in datasource changes, text in textbox will change. But when user changes text in textBox, datasource doesn't change untill some other control does not refresh data. I played with control bound to dataset and datagrid which shows data from table. When I've changed value in the control, datagrid doesn't show any changes. But when I clicked on bound column in current row of datagrid, the value was read from the control. I'd like to know if there is a way to make it without clicking in datagrid - just like all MS controls do? thanks again h.

                  I Offline
                  I Offline
                  Ista
                  wrote on last edited by
                  #8

                  yeah I had a hard time with this also. The datagrid reacts by the underlying data source having its OnListChange event fired. This forces a refresh of the data for the grid. You might try on either the change or leave event raising a changed event. This could possibly help in your situation. I'm a few days from this same situation in my app, so either way I will have to figure it out. nick I'm not an expert yet, but I play one at work. Yeah and here too.

                  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