bound controls not committed when selecting the menu bar

Hello,

I have a question in regards to binding controls (ie. TextBox). I noticed that any value in the control does not update the object it is bound to until that control loses focus. This normaly works quite well, except the following scenario:

Suppose there is an app w/ a textbox, and a save option in the menu. If a user edits a new text string into the textbox, and clicks on the menu to select the save option, the textbox still has focus and that string will not get updated into the object the control is bound to. So, if the user continues to select the save option in the menu, the text string will not get serialized out like it is expected.

Is there an easy way to force the control to lose focus upon selecting any item in the menu I imagine situations like this come up from time to time when designing applications...what's the solution

Thank you.



Answer this question

bound controls not committed when selecting the menu bar

  • Beau Button

    CommonGenius, yah, I see what you're doing. Thanks for your help!

    SG, thanks for explaining the process...I think my end may look different b/c I'm setting the bindings manualy in code. I'll just have to grab a book on WinForms to better understand setting up bindings thru the Designer.


  • Aiby

    Hey guys,

    Thanks for the response.

    Is there an event I can attach a function to that is triggered whenever any item in the menu is clicked on Idealy, I would like to call EndEdit() upon any click on the menu bar. This is b/c I have a couple of options in the menu that depend on the data being synced w/ the editors' controls.

    Sergey, can you please describe in more detail how to update the properties in the property grid->data binding->advanced I've clicked through to that option, and I'm given a grid with a list of that control's properties with a corresponding combobox. Selecting the combobox, I'm only given a "none" option. Is there something I need to do to fill those comboboxes w/ more options

    Thanks guys!


  • techno.coder

    Hi!

    You can call EndEdit() on BindingSource or you can go to the property grid, (data binding), (advanced) and there you can switch how data source updated.



  • smurrell

    You could create a handler for ending the edit, and attach it to the start of the delegate chain for each menu. The designer doesnt support multiple handlers for events; you would have to add the handlers manually, like this:



    this.myMenu1.Click += new EventHandler(this.EndEditOnMenuClick);
    this.myMenu1.Click += new EventHandler(this.myMenu1_Click);
    this.myMenu2.Click += new EventHandler(this.EndEditOnMenuClick);
    this.myMenu2.Click += new EventHandler(this.myMenu2_Click);

     

    It might be simpler just to put the ending of the edit in a method, and call that at the beginning of each menu handler that requires it.



  • ryuu_iku

    Get the binding manager for your datasource and call EndCurrentEdit before saving, e.g. this.BindingContext[myDataTable].EndCurrentEdit().



  • David De Benedetto

    too bad this forum can't embed picture, ok, I'll try to explain: select Property Grid, (data bindings), (advanced), in the dialog on the left side find property you bind (Text, must be in Common tree node), in Binding combo you already must have binding selected (if not you can do it here), in Data Source Update Mode combo you can choose to update data source (i.e. validate and save Text property) each time Text property changed (new char typed, Delete pressed...). Using such mode you do not need to worry about menu - your data source will be synchronized with text box always.

    One thing I not understand - what grid you see when you open this window I don't see a grid there - tree control, two combo and group with formatting options. Is your window named "Formatting and Advanced Binding" When I open it I sometimes hit not (data bindings) but (application settings) and get window with grid, may be you hit wrong button



  • bound controls not committed when selecting the menu bar