AdvancedBindingEditor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / AdvancedBindingEditor.cs / 1 / AdvancedBindingEditor.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Windows.Forms.Design { 
 
    using System;
    using System.ComponentModel; 
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Design; 
    using System.Windows.Forms;
 
    ///  
    /// 
    ///    Provides an editor to edit advanced binding objects. 
    /// 
    internal class AdvancedBindingEditor : UITypeEditor {

        private BindingFormattingDialog bindingFormattingDialog; 

        ///  
        ///  
        ///    Edits the specified value using the specified provider
        ///       within the specified context. 
        /// 
        public override object EditValue(ITypeDescriptorContext context,  IServiceProvider  provider, object value) {
            if (provider != null) {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); 
                IDesignerHost host = provider.GetService(typeof(IDesignerHost)) as IDesignerHost;
 
                if (edSvc != null && host != null) { 
                    if (bindingFormattingDialog == null) {
                        bindingFormattingDialog = new BindingFormattingDialog(); 
                    }

                    bindingFormattingDialog.Context = context;
                    bindingFormattingDialog.Bindings = (ControlBindingsCollection) value; 
                    bindingFormattingDialog.Host = host;
 
                    using (DesignerTransaction t = host.CreateTransaction()) { 
                        edSvc.ShowDialog(bindingFormattingDialog);
 
                        if (bindingFormattingDialog.Dirty) {
                            // since the bindings may have changed, the properties listed in the properties window
                            // need to be refreshed
                            System.Diagnostics.Debug.Assert(context.Instance is ControlBindingsCollection); 
                            TypeDescriptor.Refresh(((ControlBindingsCollection)context.Instance).BindableComponent);
 
                            if (t != null) { 
                                t.Commit();
                            } 
                        }
                        else {
                            t.Cancel();
                        } 
                    }
                } 
            } 

            return value; 
        }

        /// 
        ///  
        ///    Gets the edit style from the current context.
        ///  
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { 
            return UITypeEditorEditStyle.Modal;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK