DataGridViewComboBoxEditingControl.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 / WinForms / Managed / System / WinForms / DataGridViewComboBoxEditingControl.cs / 1 / DataGridViewComboBoxEditingControl.cs

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

namespace System.Windows.Forms 
{ 
    using System;
    using System.Drawing; 
    using System.Diagnostics;
    using System.Globalization;
    using System.Runtime.InteropServices;
 
    /// 
    [ 
        ComVisible(true), 
        ClassInterface(ClassInterfaceType.AutoDispatch)
    ] 
    public class DataGridViewComboBoxEditingControl : ComboBox, IDataGridViewEditingControl
    {
        private DataGridView dataGridView;
        private bool valueChanged; 
        private int rowIndex;
 
        ///  
        public DataGridViewComboBoxEditingControl() : base()
        { 
            this.TabStop = false;
        }

        // IDataGridViewEditingControl interface implementation 

        ///  
        public virtual DataGridView EditingControlDataGridView 
        {
            get 
            {
                return this.dataGridView;
            }
            set 
            {
                this.dataGridView = value; 
            } 
        }
 
        /// 
        public virtual object EditingControlFormattedValue
        {
            get 
            {
                return GetEditingControlFormattedValue(DataGridViewDataErrorContexts.Formatting); 
            } 
            set
            { 
                string valueStr = value as string;
                if (valueStr != null)
                {
                    this.Text = valueStr; 
                    if (String.Compare(valueStr, this.Text, true, CultureInfo.CurrentCulture) != 0)
                    { 
                        this.SelectedIndex = -1; 
                    }
                } 
            }
        }

        ///  
        public virtual int EditingControlRowIndex
        { 
            get 
            {
                return this.rowIndex; 
            }
            set
            {
                this.rowIndex = value; 
            }
        } 
 
        /// 
        public virtual bool EditingControlValueChanged 
        {
            get
            {
                return this.valueChanged; 
            }
            set 
            { 
                this.valueChanged = value;
            } 
        }

        /// 
        public virtual Cursor EditingPanelCursor 
        {
            get 
            { 
                return Cursors.Default;
            } 
        }

        /// 
        public virtual bool RepositionEditingControlOnValueChange 
        {
            get 
            { 
                return false;
            } 
        }

        /// 
        public virtual void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle) 
        {
            this.Font = dataGridViewCellStyle.Font; 
            if (dataGridViewCellStyle.BackColor.A < 255) 
            {
                // Our ComboBox does not support transparent back colors 
                Color opaqueBackColor = Color.FromArgb(255, dataGridViewCellStyle.BackColor);
                this.BackColor = opaqueBackColor;
                this.dataGridView.EditingPanel.BackColor = opaqueBackColor;
            } 
            else
            { 
                this.BackColor = dataGridViewCellStyle.BackColor; 
            }
            this.ForeColor = dataGridViewCellStyle.ForeColor; 
        }

        /// 
        public virtual bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey) 
        {
            if ((keyData & Keys.KeyCode) == Keys.Down || 
                (keyData & Keys.KeyCode) == Keys.Up || 
                (this.DroppedDown && ((keyData & Keys.KeyCode) == Keys.Escape) || (keyData & Keys.KeyCode) == Keys.Enter))
            { 
                return true;
            }
            return !dataGridViewWantsInputKey;
        } 

        ///  
        public virtual object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context) 
        {
            return this.Text; 
        }

        /// 
        public virtual void PrepareEditingControlForEdit(bool selectAll) 
        {
            if (selectAll) 
            { 
                SelectAll();
            } 
        }

        private void NotifyDataGridViewOfValueChange()
        { 
            this.valueChanged = true;
            this.dataGridView.NotifyCurrentCellDirty(true); 
        } 

        ///  
        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            base.OnSelectedIndexChanged(e);
            if (this.SelectedIndex != -1) 
            {
                NotifyDataGridViewOfValueChange(); 
            } 
        }
    } 
}

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