I am building a form in which every control databinds to a property of a different class and I have found that there are some controls that simply will not lose focus when I try to leave the control. For example, I have a numericUpDown control that is databound to a property on a seperate class, and if I click in the numericUpDown, it will gain focus, however if I click outside the control, it will not lose focus. I cannot access other controls on the form and I cannot exit the form. The X button on the top right corner simply does nothing and the numericUpDown still has focus.
When I tried debugging through to see exactly what was happening, I saw that whenever I tried to leave the control, the "Leave" event was invoked, the databound value was being updated, however immediately afterwards, the "Enter" event was invoked.
Here's the code for the databind for the numericUpDown that I was talking about. The numericUpDown is named "Major_Tick_Number" and is bound to the property MajorTicks in theDial.Representation:
Major_Tick_Number.DataBindings.Add("Value", theDial.Representation, "MajorTicks");
And here's the designer code for it:
this.Major_Tick_Number.Location = new System.Drawing.Point(195, 17);
this.Major_Tick_Number.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.Major_Tick_Number.Name = "Major_Tick_Number";
this.Major_Tick_Number.Size = new System.Drawing.Size(46, 20);
this.Major_Tick_Number.TabIndex = 63;
this.Major_Tick_Number.Value = new decimal(new int[] {
10,
0,
0,
0});
Again, the databind works fine in the sense that the value is being updated, but the control simply will not lose focus.
If I remove the databind, the control gains and loses focus normally.
Somethings I'd like to note: I'm using Visual Studio 2008 and am programming in C#. Also, my form has a tabControl, and all my other controls are on the tabControl, not sure if that matters. Also, I'd like to emphasize that some controls (maybe 25%) are working fine and some have the focus issue, and I cannot really see any pattern in which controls work and which do not work.
Please let me know if you need more information. Any help, suggestions you can provide will be greatly appreciated.
Thank you.
Here's the property to which it is databound
public float MajorTicks {
get { return otherObject.getMajorTicks(); }
set { otherObject.setMajorTicks(value); }
}
and in the otherObject (written in managed c++)
float getMajorTicks() {return majorTicks;};
void setMajorTicks(float val) {majorTicks = val;};