Export (0) Print
Expand All
5 out of 6 rated this helpful - Rate this topic

DataGridViewComboBoxEditingControl Class

Represents the hosted combo box control in a DataGridViewComboBoxCell.

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

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

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 combo = e.Control as ComboBox;
    if (combo != null)
    {
        // Remove an existing event-handler, if present, to avoid 
        // adding multiple handlers when the editing control is reused.
        combo.SelectedIndexChanged -=
            new EventHandler(ComboBox_SelectedIndexChanged);

        // Add the event handler. 
        combo.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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.