locked
Data bound control won't lose focus RRS feed

  • Question

  • Hello,

    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":

    Major_Tick_Number.DataBindings.Add(

    "Value", theDial.Representation, "MajorTicks");

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

    Any help, suggestions you can provide will be greatly appreciated.

    Thank you.



    Tuesday, July 26, 2011 3:07 PM

All replies

  • Any advice/help would be really helpful here as I have been working for a few days on this problem now with nothing to show for it. 
    I found a few questions on stackoverflow about a similar problem, but those are limited to combo-boxes.  Also I cannot remove the databind or turn off causesvalidation because I need both to work. 

    Stackoverflow questions:
    http://stackoverflow.com/questions/1219395/combobox-not-losing-focus
    http://stackoverflow.com/questions/290629/cannot-tab-out-of-databound-winforms-dropdown-list

    Friday, July 29, 2011 6:43 PM
  • Hello etk1220,

    Where did you put the databinding for the NumericUpDown control?

    I made a sample that do the binding (bind a TextBox's Text property to the NumericUpDown control) in a button's click event, and it works right without the focus issue like yours, so I guess that is cause by your class "theDial.Representation". What is the class like? Would you please post a demo that can shortly and explicitly reproduce the problem? Or you can have a try to create a new clean project and create the data source class, and bind it that way. It's very likely that you will find the problem while trying to reproduce the issue on a clean project.

    Sincerely,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 1, 2011 3:47 AM
  • Hi etk1220,

    How's the issue going on? Was it been solved yet? If so, would you mind share your solution with us?

    Sincerely,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by sujitkkumar Wednesday, November 28, 2012 9:34 AM
    • Unproposed as answer by sujitkkumar Wednesday, November 28, 2012 9:34 AM
    Tuesday, August 9, 2011 5:35 AM
  • Even i was facing the same situation with my textbox control which was bound with a long datatype but i overcame it by setting the CausesValidtion property of the control to False.
    • Edited by sujitkkumar Wednesday, November 28, 2012 9:33 AM
    Wednesday, November 28, 2012 9:33 AM