Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ToolStrip buttons don't fire TextBox Leave events
Message
From
27/06/2006 20:37:08
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
ToolStrip buttons don't fire TextBox Leave events
Miscellaneous
Thread ID:
01132234
Message ID:
01132234
Views:
285
I was able to figure out adding a button to mmNavigationToolStrip (code below).
The problem is, when you click on a button in the tool strip, any changes in the current TextBox are NOT updated. I.e., the TextBox Leave event isn't firing. The cursor stays in the textbox when you click a toolstrip button (which makes UI sense).

So, for a Save button, it looks like it saves, but when you close the screen, it asks you if you want to save changes...

I'm a winforms newbie, is there any way to force the last event in a toolstrip click?

I tried setting the toolstrip CausesValidation property = true, but that didn't help.

Thanks!

[edit - partial solution]
from: http://www.ideablade.com/techtip_Forcing_databinding_completion%20.htm
You must add a line of code to your button handler to ensure that a pending DataBinding completes. The handler must tell the Form (or UserControl) to "validate" itself by calling its Validate() method.

So... off to a movie, but
1) the mmToolStripButtonSave should (have a property setting to...) find out it's container's parent form and Validate()
2) I'll subclass mmToolStripButtonSave later and see if I can get it to work.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Reflection;
using System.Windows.Forms;

using OakLeaf.MM.Main.Builders;
using OakLeaf.MM.Main.Business;
using OakLeaf.MM.Main.Globalization;
using OakLeaf.MM.Main.Windows.Forms;

namespace MyApp.Windows.Forms.Controls
{
    /// <summary>
    /// myNavigationToolStrip
    /// </summary>
    public partial class myNavigationToolStrip : mmNavigationToolStrip
    {
        public mmToolStripButtonSave btnSave;

        /// <summary>
        /// Constructor
        /// </summary>
        public myNavigationToolStrip()
        {
            InitializeComponent();

            btnSave = new mmToolStripButtonSave();

            // code to load image in project as Embedded Resource
            // +++ make into function
            string bmpName = "MyApp.Windows.Forms.Resources.save.bmp";
            System.IO.Stream strm = null;
            try
            {
                strm = this.GetType().Assembly.GetManifestResourceStream(bmpName);
                btnSave.Image = new Bitmap(strm);                
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                if (strm != null)
                    strm.Close();
            }

            this.SuspendLayout();
            this.Items.Add(btnSave);
            this.ResumeLayout(false);
        }
    }
}
Next
Reply
Map
View

Click here to load this message in the networking platform