Export (0) Print
Expand All

DataGridViewComboBoxEditingControl Class

Note: This class is new in the .NET Framework version 2.0.

Represents the hosted combo box control in a DataGridViewComboBoxCell.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class DataGridViewComboBoxEditingControl : ComboBox, IDataGridViewEditingControl
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class DataGridViewComboBoxEditingControl extends ComboBox implements IDataGridViewEditingControl
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class DataGridViewComboBoxEditingControl extends ComboBox implements IDataGridViewEditingControl

The DataGridViewComboBoxEditingControl class is a specialized type of ComboBox that implements the IDataGridViewEditingControl interface, allowing it to be hosted in a DataGridViewComboBoxCell when the cell is in edit mode. When a DataGridViewComboBoxCell is in edit mode, you can retrieve the DataGridViewComboBoxEditingControl through the EditingControl property of the DataGridView control.

Handle the EditingControlShowing event to perform custom initialization of the editing control when a cell enters edit mode. To customize the display characteristics of the control, set the properties of the object returned by the DataGridViewEditingControlShowingEventArgs.CellStyle property rather than setting the properties of the control returned by the DataGridViewEditingControlShowingEventArgs.Control property.

The following code example demonstrates how to use an DataGridView.EditingControlShowing event handler to add a handler for a DataGridViewComboBoxEditingControl event. In the example, the editing control is cast to a ComboBox to handle the ComboBox.SelectedIndexChanged event.

private DataGridView dataGridView1 = new DataGridView();

private void AddColorColumn()
{
    DataGridViewComboBoxColumn comboBoxColumn =
        new DataGridViewComboBoxColumn();
    comboBoxColumn.Items.AddRange(
        Color.Red, Color.Yellow, Color.Green, Color.Blue);
    comboBoxColumn.ValueType = typeof(Color);
    dataGridView1.Columns.Add(comboBoxColumn);
    dataGridView1.EditingControlShowing +=
        new DataGridViewEditingControlShowingEventHandler(
        dataGridView1_EditingControlShowing);
}

private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
{
    ((ComboBox)e.Control).SelectedIndexChanged +=
        new EventHandler(ComboBox_SelectedIndexChanged);
}

private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    ((ComboBox)sender).BackColor = (Color)((ComboBox)sender).SelectedItem;
}

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ListControl
           System.Windows.Forms.ComboBox
            System.Windows.Forms.DataGridViewComboBoxEditingControl

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft