DataGridColumnStyleMappingNameEditor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / DataGridColumnStyleMappingNameEditor.cs / 1 / DataGridColumnStyleMappingNameEditor.cs

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

namespace System.Windows.Forms.Design { 
 
    using System.Design;
    using System; 
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Drawing;
    using System.Drawing.Design; 

    internal class DataGridColumnStyleMappingNameEditor : UITypeEditor { 
 
        // FxCop made me add this constructor
        private DataGridColumnStyleMappingNameEditor() : base() {} 
        private DesignBindingPicker designBindingPicker;

        public override bool IsDropDownResizable {
            get { 
                return true;
            } 
        } 

        public override object EditValue(ITypeDescriptorContext context,  IServiceProvider  provider, object value) { 
            if (provider != null && context.Instance != null) {
                object instance = context.Instance;
                DataGridColumnStyle columnStyle = (DataGridColumnStyle) context.Instance;
                if (columnStyle.DataGridTableStyle == null || columnStyle.DataGridTableStyle.DataGrid == null) 
                    return value;
                PropertyDescriptor dataSourceProperty = TypeDescriptor.GetProperties(columnStyle.DataGridTableStyle.DataGrid)["DataSource"]; 
                if (dataSourceProperty != null) { 
                    object dataSource = dataSourceProperty.GetValue(columnStyle.DataGridTableStyle.DataGrid);
                    if (designBindingPicker == null) { 
                        designBindingPicker = new DesignBindingPicker();
                    }
                    DesignBinding oldSelection = new DesignBinding(null, (string) value);
                    DesignBinding newSelection = designBindingPicker.Pick(context, provider, 
                                                                          false, /* showDataSources   */
                                                                          true,  /* showDataMembers   */ 
                                                                          false, /* selectListMembers */ 
                                                                          dataSource, String.Empty,
                                                                          oldSelection); 
                    if (dataSource != null && newSelection != null) {
                        if (String.IsNullOrEmpty(newSelection.DataMember) || newSelection.DataMember == null)
                            value = "";
                        else 
                            value = newSelection.DataField;
 
                    } 
                }
            } 

            return value;
        }
 
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
            return UITypeEditorEditStyle.DropDown; 
        } 
    }
} 

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