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