.NET Framework Class Library DataGridViewComboBoxCell Class

Inheritance Hierarchy
Namespace:
System.Windows.Forms
Assembly:
System.Windows.Forms (in System.Windows.Forms.dll)

Syntax
Public Class DataGridViewComboBoxCell _
Inherits DataGridViewCell
public class DataGridViewComboBoxCell : DataGridViewCell
public ref class DataGridViewComboBoxCell : public DataGridViewCell
type DataGridViewComboBoxCell =
class
inherit DataGridViewCell
end
The DataGridViewComboBoxCell type exposes the following members.

Constructors

Properties

Methods
|
| Name | Description |
|---|
.gif) | AdjustCellBorderStyle | Modifies the input cell border style according to the specified criteria. (Inherited from DataGridViewCell.) | .gif) | BorderWidths | Returns a Rectangle that represents the widths of all the cell margins. (Inherited from DataGridViewCell.) | .gif) | ClickUnsharesRow | Indicates whether the cell's row will be unshared when the cell is clicked. (Inherited from DataGridViewCell.) | .gif) | Clone | Creates an exact copy of this cell. (Overrides DataGridViewCell..::.Clone()()().) | .gif) | ContentClickUnsharesRow | Indicates whether the cell's row will be unshared when the cell's content is clicked. (Inherited from DataGridViewCell.) | .gif) | ContentDoubleClickUnsharesRow | Indicates whether the cell's row will be unshared when the cell's content is double-clicked. (Inherited from DataGridViewCell.) | .gif) | CreateAccessibilityInstance | Creates a new accessible object for the DataGridViewCell. (Inherited from DataGridViewCell.) | .gif) | DetachEditingControl | Removes the cell's editing control from the DataGridView. (Overrides DataGridViewCell..::.DetachEditingControl()()().) | .gif) | Dispose()()() | Releases all resources used by the DataGridViewCell. (Inherited from DataGridViewCell.) | .gif) | Dispose(Boolean) | Releases the unmanaged resources used by the DataGridViewCell and optionally releases the managed resources. (Inherited from DataGridViewCell.) | .gif) | DoubleClickUnsharesRow | Indicates whether the cell's row will be unshared when the cell is double-clicked. (Inherited from DataGridViewCell.) | .gif) | EnterUnsharesRow | Indicates whether the parent row will be unshared when the focus moves to the cell. (Inherited from DataGridViewCell.) | .gif) | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | .gif) | Finalize | Releases the unmanaged resources and performs other cleanup operations before the DataGridViewCell is reclaimed by garbage collection. (Inherited from DataGridViewCell.) | .gif) | GetClipboardContent | Retrieves the formatted value of the cell to copy to the Clipboard. (Inherited from DataGridViewCell.) | .gif) | GetContentBounds(Int32) | Returns the bounding rectangle that encloses the cell's content area using a default Graphics and cell style currently in effect for the cell. (Inherited from DataGridViewCell.) | .gif) | GetContentBounds(Graphics, DataGridViewCellStyle, Int32) | Returns the bounding rectangle that encloses the cell's content area, which is calculated using the specified Graphics and cell style. (Overrides DataGridViewCell..::.GetContentBounds(Graphics, DataGridViewCellStyle, Int32).) | .gif) | GetEditedFormattedValue | Returns the current, formatted value of the cell, regardless of whether the cell is in edit mode and the value has not been committed. (Inherited from DataGridViewCell.) | .gif) | GetErrorIconBounds | Returns the bounding rectangle that encloses the cell's error icon, if one is displayed. (Overrides DataGridViewCell..::.GetErrorIconBounds(Graphics, DataGridViewCellStyle, Int32).) | .gif) | GetErrorText | Returns a string that represents the error for the cell. (Inherited from DataGridViewCell.) | .gif) | GetFormattedValue | Gets the formatted value of the cell's data. (Overrides DataGridViewCell..::.GetFormattedValue(Object, Int32, DataGridViewCellStyle%, TypeConverter, TypeConverter, DataGridViewDataErrorContexts).) | .gif) | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | .gif) | GetInheritedContextMenuStrip | Gets the inherited shortcut menu for the current cell. (Inherited from DataGridViewCell.) | .gif) | GetInheritedState | Returns a value indicating the current state of the cell as inherited from the state of its row and column. (Inherited from DataGridViewCell.) | .gif) | GetInheritedStyle | Gets the style applied to the cell. (Inherited from DataGridViewCell.) | .gif) | GetPreferredSize | Calculates the preferred size, in pixels, of the cell. (Overrides DataGridViewCell..::.GetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size).) | .gif) | GetSize | Gets the size of the cell. (Inherited from DataGridViewCell.) | .gif) | GetType | Gets the Type of the current instance. (Inherited from Object.) | .gif) | GetValue | Gets the value of the cell. (Inherited from DataGridViewCell.) | .gif) | InitializeEditingControl | Attaches and initializes the hosted editing control. (Overrides DataGridViewCell..::.InitializeEditingControl(Int32, Object, DataGridViewCellStyle).) | .gif) | KeyDownUnsharesRow | Indicates whether the parent row is unshared if the user presses a key while the focus is on the cell. (Inherited from DataGridViewCell.) | .gif) | KeyEntersEditMode | Determines if edit mode should be started based on the given key. (Overrides DataGridViewCell..::.KeyEntersEditMode(KeyEventArgs).) | .gif) | KeyPressUnsharesRow | Indicates whether a row will be unshared if a key is pressed while a cell in the row has focus. (Inherited from DataGridViewCell.) | .gif) | KeyUpUnsharesRow | Indicates whether the parent row is unshared when the user releases a key while the focus is on the cell. (Inherited from DataGridViewCell.) | .gif) | LeaveUnsharesRow | Indicates whether a row will be unshared when the focus leaves a cell in the row. (Inherited from DataGridViewCell.) | .gif) | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | .gif) | MouseClickUnsharesRow | Indicates whether a row will be unshared if the user clicks a mouse button while the pointer is on a cell in the row. (Inherited from DataGridViewCell.) | .gif) | MouseDoubleClickUnsharesRow | Indicates whether a row will be unshared if the user double-clicks a cell in the row. (Inherited from DataGridViewCell.) | .gif) | MouseDownUnsharesRow | Indicates whether a row will be unshared when the user holds down a mouse button while the pointer is on a cell in the row. (Inherited from DataGridViewCell.) | .gif) | MouseEnterUnsharesRow | Indicates whether a row will be unshared when the mouse pointer moves over a cell in the row. (Inherited from DataGridViewCell.) | .gif) | MouseLeaveUnsharesRow | Indicates whether a row will be unshared when the mouse pointer leaves the row. (Inherited from DataGridViewCell.) | .gif) | MouseMoveUnsharesRow | Indicates whether a row will be unshared when the mouse pointer moves over a cell in the row. (Inherited from DataGridViewCell.) | .gif) | MouseUpUnsharesRow | Indicates whether a row will be unshared when the user releases a mouse button while the pointer is on a cell in the row. (Inherited from DataGridViewCell.) | .gif) | OnClick | Called when the cell is clicked. (Inherited from DataGridViewCell.) | .gif) | OnContentClick | Called when the cell's contents are clicked. (Inherited from DataGridViewCell.) | .gif) | OnContentDoubleClick | Called when the cell's contents are double-clicked. (Inherited from DataGridViewCell.) | .gif) | OnDataGridViewChanged | Called when the DataGridView property of the cell changes. (Overrides DataGridViewCell..::.OnDataGridViewChanged()()().) | .gif) | OnDoubleClick | Called when the cell is double-clicked. (Inherited from DataGridViewCell.) | .gif) | OnEnter | Called when the focus moves to a cell. (Overrides DataGridViewCell..::.OnEnter(Int32, Boolean).) | .gif) | OnKeyDown | Called when a character key is pressed while the focus is on a cell. (Inherited from DataGridViewCell.) | .gif) | OnKeyPress | Called when a key is pressed while the focus is on a cell. (Inherited from DataGridViewCell.) | .gif) | OnKeyUp | Called when a character key is released while the focus is on a cell. (Inherited from DataGridViewCell.) | .gif) | OnLeave | Called when the focus moves from a cell. (Overrides DataGridViewCell..::.OnLeave(Int32, Boolean).) | .gif) | OnMouseClick | Called when the user clicks a mouse button while the pointer is on a cell. (Overrides DataGridViewCell..::.OnMouseClick(DataGridViewCellMouseEventArgs).) | .gif) | OnMouseDoubleClick | Called when the user double-clicks a mouse button while the pointer is on a cell. (Inherited from DataGridViewCell.) | .gif) | OnMouseDown | Called when the user holds down a mouse button while the pointer is on a cell. (Inherited from DataGridViewCell.) | .gif) | OnMouseEnter | Called when the mouse pointer moves over a cell. (Overrides DataGridViewCell..::.OnMouseEnter(Int32).) | .gif) | OnMouseLeave | Called when the mouse pointer leaves the cell. (Overrides DataGridViewCell..::.OnMouseLeave(Int32).) | .gif) | OnMouseMove | Called when the mouse pointer moves within a cell. (Overrides DataGridViewCell..::.OnMouseMove(DataGridViewCellMouseEventArgs).) | .gif) | OnMouseUp | Called when the user releases a mouse button while the pointer is on a cell. (Inherited from DataGridViewCell.) | .gif) | Paint | Paints the current DataGridViewComboBoxCell. (Overrides DataGridViewCell..::.Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts).) | .gif) | PaintBorder | Paints the border of the current DataGridViewCell. (Inherited from DataGridViewCell.) | .gif) | PaintErrorIcon | Paints the error icon of the current DataGridViewCell. (Inherited from DataGridViewCell.) | .gif) | ParseFormattedValue | Converts a value formatted for display to an actual cell value. (Overrides DataGridViewCell..::.ParseFormattedValue(Object, DataGridViewCellStyle, TypeConverter, TypeConverter).) | .gif) | PositionEditingControl | Sets the location and size of the editing control hosted by a cell in the DataGridView control. (Inherited from DataGridViewCell.) | .gif) | PositionEditingPanel | Sets the location and size of the editing panel hosted by the cell, and returns the normal bounds of the editing control within the editing panel. (Inherited from DataGridViewCell.) | .gif) | RaiseCellClick | Raises the DataGridView..::.CellClick event. (Inherited from DataGridViewElement.) | .gif) | RaiseCellContentClick | Raises the DataGridView..::.CellContentClick event. (Inherited from DataGridViewElement.) | .gif) | RaiseCellContentDoubleClick | Raises the DataGridView..::.CellContentDoubleClick event. (Inherited from DataGridViewElement.) | .gif) | RaiseCellValueChanged | Raises the DataGridView..::.CellValueChanged event. (Inherited from DataGridViewElement.) | .gif) | RaiseDataError | Raises the DataGridView..::.DataError event. (Inherited from DataGridViewElement.) | .gif) | RaiseMouseWheel | Raises the Control..::.MouseWheel event. (Inherited from DataGridViewElement.) | .gif) | SetValue | Sets the value of the cell. (Inherited from DataGridViewCell.) | .gif) | ToString | Returns a string that describes the current object. (Overrides DataGridViewCell..::.ToString()()().) | Top

Remarks
The DataGridViewComboBoxCell class is a specialized type of DataGridViewCell used to display a combo box control, which is an editing field combined with a list selection field. The currently selected DataGridViewComboBoxCell hosts a DataGridViewComboBoxEditingControl in which the user can change the cell's value, assuming the cell's ReadOnly property is set to false. Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property. The DataGridViewComboBoxColumn is the column type specialized to hold cells of this type. By default, the DataGridViewComboBoxColumn..::.CellTemplate is initialized to a new DataGridViewComboBoxCell. To pattern the cells within a column after an existing DataGridViewComboBoxCell, set the column's CellTemplate property to the cell to use as a pattern. The cell-related properties of the column are wrappers for the similarly-named properties of the template cell. Changing the property values of the template cell will affect only cells based on the template that are added after the change. Changing the cell-related property values of the column, however, will update the template cell and all other cells in the column, and refresh the column display if necessary. You will typically work with the DataGridViewComboBoxColumn type unless you want to override column values for specific cells. The guidelines described in the DataGridViewComboBoxColumn class overview topic for populating the drop-down list applies to both cell and column instances. Notes to InheritorsWhen you derive from DataGridViewComboBoxCell and add new properties to the derived class, be sure to override the Clone method to copy the new properties during cloning operations. You should also call the base class's Clone method so that the properties of the base class are copied to the new cell.

Examples
The following code example demonstrates the DataGridViewComboBoxColumn class, which makes use of the DataGridViewComboBoxCell class. You can set the cell DataSource, ValueMember, and DisplayMember properties in the same way that the corresponding column properties are set in this example. This example is part of a larger example available in the DataGridViewComboBoxColumn class overview topic.
Private Function CreateComboBoxColumn() _
As DataGridViewComboBoxColumn
Dim column As New DataGridViewComboBoxColumn()
With column
.DataPropertyName = ColumnName.TitleOfCourtesy.ToString()
.HeaderText = ColumnName.TitleOfCourtesy.ToString()
.DropDownWidth = 160
.Width = 90
.MaxDropDownItems = 3
.FlatStyle = FlatStyle.Flat
End With
Return column
End Function
Private Sub SetAlternateChoicesUsingDataSource( _
ByVal comboboxColumn As DataGridViewComboBoxColumn)
With comboboxColumn
.DataSource = RetrieveAlternativeTitles()
.ValueMember = ColumnName.TitleOfCourtesy.ToString()
.DisplayMember = .ValueMember
End With
End Sub
Private Function RetrieveAlternativeTitles() As DataTable
Return Populate( _
"SELECT distinct TitleOfCourtesy FROM Employees")
End Function
Private connectionString As String = _
"Integrated Security=SSPI;Persist Security Info=False;" _
& "Initial Catalog=Northwind;Data Source=localhost"
Private Function Populate(ByVal sqlCommand As String) As DataTable
Dim northwindConnection As New SqlConnection(connectionString)
northwindConnection.Open()
Dim command As New SqlCommand(sqlCommand, _
northwindConnection)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = command
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
adapter.Fill(table)
Return table
End Function
' Using an enum provides some abstraction between column index
' and column name along with compile time checking, and gives
' a handy place to store the column names.
Enum ColumnName
EmployeeId
LastName
FirstName
Title
TitleOfCourtesy
BirthDate
HireDate
Address
City
Region
PostalCode
Country
HomePhone
Extension
Photo
Notes
ReportsTo
PhotoPath
OutOfOffice
End Enum
private DataGridViewComboBoxColumn CreateComboBoxColumn()
{
DataGridViewComboBoxColumn column =
new DataGridViewComboBoxColumn();
{
column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
column.DropDownWidth = 160;
column.Width = 90;
column.MaxDropDownItems = 3;
column.FlatStyle = FlatStyle.Flat;
}
return column;
}
private void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn comboboxColumn)
{
{
comboboxColumn.DataSource = RetrieveAlternativeTitles();
comboboxColumn.ValueMember = ColumnName.TitleOfCourtesy.ToString();
comboboxColumn.DisplayMember = comboboxColumn.ValueMember;
}
}
private DataTable RetrieveAlternativeTitles()
{
return Populate("SELECT distinct TitleOfCourtesy FROM Employees");
}
string connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
private DataTable Populate(string sqlCommand)
{
SqlConnection northwindConnection = new SqlConnection(connectionString);
northwindConnection.Open();
SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
return table;
}
// Using an enum provides some abstraction between column index
// and column name along with compile time checking, and gives
// a handy place to store the column names.
enum ColumnName
{
EmployeeId,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath,
OutOfOffice
};
private:
DataGridViewComboBoxColumn^ CreateComboBoxColumn()
{
DataGridViewComboBoxColumn^ column =
gcnew DataGridViewComboBoxColumn();
{
column->DataPropertyName = ColumnName::TitleOfCourtesy.ToString();
column->HeaderText = ColumnName::TitleOfCourtesy.ToString();
column->DropDownWidth = 160;
column->Width = 90;
column->MaxDropDownItems = 3;
column->FlatStyle = FlatStyle::Flat;
}
return column;
}
private:
void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn^ comboboxColumn)
{
{
comboboxColumn->DataSource = RetrieveAlternativeTitles();
comboboxColumn->ValueMember = ColumnName::TitleOfCourtesy.ToString();
comboboxColumn->DisplayMember = comboboxColumn->ValueMember;
}
}
private:
DataTable^ RetrieveAlternativeTitles()
{
return Populate("SELECT distinct TitleOfCourtesy FROM Employees");
}
String^ connectionString;
private:
DataTable^ Populate(String^ sqlCommand)
{
SqlConnection^ northwindConnection = gcnew SqlConnection(connectionString);
northwindConnection->Open();
SqlCommand^ command = gcnew SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter^ adapter = gcnew SqlDataAdapter();
adapter->SelectCommand = command;
DataTable^ table = gcnew DataTable();
adapter->Fill(table);
return table;
}
// Using an enum provides some abstraction between column index
// and column name along with compile time checking, and gives
// a handy place to store the column names.
enum class ColumnName
{
EmployeeID,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath,
OutOfOffice
};

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0 .NET Framework Client ProfileSupported in: 4, 3.5 SP1

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

See Also
|
Biblioteca de clases de .NET Framework DataGridViewComboBoxCell (Clase)

Jerarquía de herencia
Espacio de nombres:
System.Windows.Forms
Ensamblado:
System.Windows.Forms (en System.Windows.Forms.dll)

Sintaxis
Public Class DataGridViewComboBoxCell _
Inherits DataGridViewCell
public class DataGridViewComboBoxCell : DataGridViewCell
public ref class DataGridViewComboBoxCell : public DataGridViewCell
type DataGridViewComboBoxCell =
class
inherit DataGridViewCell
end
El tipo DataGridViewComboBoxCell expone los siguientes miembros.

Constructores

Propiedades

Métodos
|
| Nombre | Descripción |
|---|
.gif) | AdjustCellBorderStyle | Modifica el estilo de borde de celda de entrada según los criterios especificados. (Se hereda de DataGridViewCell). | .gif) | BorderWidths | Devuelve un objeto Rectangle que representa el ancho de todos los márgenes de la celda. (Se hereda de DataGridViewCell). | .gif) | ClickUnsharesRow | Indica si la fila de la celda dejará de estar compartida al hacer clic en la celda. (Se hereda de DataGridViewCell). | .gif) | Clone | Crea una copia exacta de esta celda. (Invalida a DataGridViewCell..::.Clone()()()). | .gif) | ContentClickUnsharesRow | Indica si la fila de la celda dejará de estar compartida al hacer clic en el contenido de la celda. (Se hereda de DataGridViewCell). | .gif) | ContentDoubleClickUnsharesRow | Indica si la fila de la celda dejará de estar compartida al hacer doble clic en el contenido de la celda. (Se hereda de DataGridViewCell). | .gif) | CreateAccessibilityInstance | Crea un nuevo objeto accesible para la celda DataGridViewCell. (Se hereda de DataGridViewCell). | .gif) | DetachEditingControl | Quita el control de edición de la celda de DataGridView. (Invalida a DataGridViewCell..::.DetachEditingControl()()()). | .gif) | Dispose()()() | Libera todos los recursos utilizados por el objeto DataGridViewCell. (Se hereda de DataGridViewCell). | .gif) | Dispose(Boolean) | Libera los recursos no administrados que utiliza DataGridViewCell y, opcionalmente, libera los recursos administrados. (Se hereda de DataGridViewCell). | .gif) | DoubleClickUnsharesRow | Indica si la fila de la celda dejará de estar compartida al hacer doble clic en la celda. (Se hereda de DataGridViewCell). | .gif) | EnterUnsharesRow | Indica si la fila primaria va a dejar de estar compartida cuando el foco se desplace a la celda. (Se hereda de DataGridViewCell). | .gif) | Equals(Object) | Determina si el objeto Object especificado es igual al objeto Object actual. (Se hereda de Object). | .gif) | Finalize | Libera los recursos no administrados y realiza otras operaciones de limpieza antes de que el recolector de elementos no utilizados reclame DataGridViewCell. (Se hereda de DataGridViewCell). | .gif) | GetClipboardContent | Recupera el valor con formato de la celda que copiar en el Clipboard. (Se hereda de DataGridViewCell). | .gif) | GetContentBounds(Int32) | Devuelve el rectángulo delimitador que rodea el área de contenido de la celda utilizando un objeto Graphics predeterminado y el estilo de celda actualmente en vigor para la celda. (Se hereda de DataGridViewCell). | .gif) | GetContentBounds(Graphics, DataGridViewCellStyle, Int32) | Devuelve el rectángulo delimitador que rodea el área de contenido de la celda, que se calcula utilizando el objeto Graphics especificado y el estilo de celda. (Invalida a DataGridViewCell..::.GetContentBounds(Graphics, DataGridViewCellStyle, Int32)). | .gif) | GetEditedFormattedValue | Devuelve el valor actual con formato de la celda, con independencia de si la celda está en modo de edición y no se ha confirmado el valor. (Se hereda de DataGridViewCell). | .gif) | GetErrorIconBounds | Devuelve el rectángulo delimitador que rodea el icono de error de la celda, si se muestra alguno. (Invalida a DataGridViewCell..::.GetErrorIconBounds(Graphics, DataGridViewCellStyle, Int32)). | .gif) | GetErrorText | Devuelve una cadena que representa el error para la celda. (Se hereda de DataGridViewCell). | .gif) | GetFormattedValue | Obtiene el valor con formato de los datos de la celda. (Invalida a DataGridViewCell..::.GetFormattedValue(Object, Int32, DataGridViewCellStyle%, TypeConverter, TypeConverter, DataGridViewDataErrorContexts)). | .gif) | GetHashCode | Actúa como función hash para un tipo concreto. (Se hereda de Object). | .gif) | GetInheritedContextMenuStrip | Obtiene el menú contextual heredado para la celda actual. (Se hereda de DataGridViewCell). | .gif) | GetInheritedState | Devuelve un valor que indica el estado actual de la celda tal como lo hereda del estado de su fila y columna. (Se hereda de DataGridViewCell). | .gif) | GetInheritedStyle | Obtiene el estilo aplicado a la celda. (Se hereda de DataGridViewCell). | .gif) | GetPreferredSize | Calcula el tamaño preferido, en píxeles, de la celda. (Invalida a DataGridViewCell..::.GetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size)). | .gif) | GetSize | Obtiene el tamaño de la celda. (Se hereda de DataGridViewCell). | .gif) | GetType | Obtiene el objeto Type de la instancia actual. (Se hereda de Object). | .gif) | GetValue | Obtiene el valor de la celda. (Se hereda de DataGridViewCell). | .gif) | InitializeEditingControl | Adjunta e inicializa el control de edición hospedado. (Invalida a DataGridViewCell..::.InitializeEditingControl(Int32, Object, DataGridViewCellStyle)). | .gif) | KeyDownUnsharesRow | Indica si la fila primaria deja de estar compartida cuando el usuario presiona una tecla mientras el foco está en la celda. (Se hereda de DataGridViewCell). | .gif) | KeyEntersEditMode | Determina si el modo de edición se debe iniciar basándose en la clave dada. (Invalida a DataGridViewCell..::.KeyEntersEditMode(KeyEventArgs)). | .gif) | KeyPressUnsharesRow | Indica si una fila va a dejar de estar compartida cuando se presiona una tecla mientras el foco está en una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | KeyUpUnsharesRow | Indica si la fila primaria deja de estar compartida cuando el usuario libera una tecla mientras el foco está en la celda. (Se hereda de DataGridViewCell). | .gif) | LeaveUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el foco abandone una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | MemberwiseClone | Crea una copia superficial del objeto Object actual. (Se hereda de Object). | .gif) | MouseClickUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el usuario haga clic en un botón del mouse mientras el puntero está en una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | MouseDoubleClickUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el usuario haga doble clic en una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | MouseDownUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el usuario mantiene presionado un botón del mouse mientras el puntero está en una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | MouseEnterUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el puntero del mouse se sitúe sobre una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | MouseLeaveUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el puntero del mouse salga de la fila. (Se hereda de DataGridViewCell). | .gif) | MouseMoveUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el puntero del mouse se sitúe sobre una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | MouseUpUnsharesRow | Indica si una fila va a dejar de estar compartida cuando el usuario suelta un botón del mouse mientras el puntero está en una celda de la fila. (Se hereda de DataGridViewCell). | .gif) | OnClick | Se le llama al hacer clic en la celda. (Se hereda de DataGridViewCell). | .gif) | OnContentClick | Se le llama al hacer clic en el contenido de la celda. (Se hereda de DataGridViewCell). | .gif) | OnContentDoubleClick | Se le llama al hacer doble clic en el contenido de la celda. (Se hereda de DataGridViewCell). | .gif) | OnDataGridViewChanged | Se le llama cuando cambia la propiedad DataGridView de la celda. (Invalida a DataGridViewCell..::.OnDataGridViewChanged()()()). | .gif) | OnDoubleClick | Se le llama al hacer doble clic en la celda. (Se hereda de DataGridViewCell). | .gif) | OnEnter | Se le llama cuando el foco se desplaza a una celda. (Invalida a DataGridViewCell..::.OnEnter(Int32, Boolean)). | .gif) | OnKeyDown | Se le llama cuando se presiona una tecla de carácter mientras el foco está en una celda. (Se hereda de DataGridViewCell). | .gif) | OnKeyPress | Se le llama cuando se presiona una tecla mientras el foco está en una celda. (Se hereda de DataGridViewCell). | .gif) | OnKeyUp | Se le llama cuando se suelta una tecla de carácter mientras el foco está en una celda. (Se hereda de DataGridViewCell). | .gif) | OnLeave | Se le llama cuando el foco se desplaza de una celda. (Invalida a DataGridViewCell..::.OnLeave(Int32, Boolean)). | .gif) | OnMouseClick | Se le llama cuando el usuario hace clic en un botón del mouse mientras el puntero está en una celda. (Invalida a DataGridViewCell..::.OnMouseClick(DataGridViewCellMouseEventArgs)). | .gif) | OnMouseDoubleClick | Se le llama cuando el usuario hace clic en un botón del mouse mientras el puntero está en una celda. (Se hereda de DataGridViewCell). | .gif) | OnMouseDown | Se le llama cuando el usuario mantiene presionado un botón del mouse mientras el puntero está en una celda. (Se hereda de DataGridViewCell). | .gif) | OnMouseEnter | Se le llama cuando el puntero del mouse se mueve sobre una celda. (Invalida a DataGridViewCell..::.OnMouseEnter(Int32)). | .gif) | OnMouseLeave | Se le llama cuando el puntero del mouse sale de la celda. (Invalida a DataGridViewCell..::.OnMouseLeave(Int32)). | .gif) | OnMouseMove | Se le llama cuando el puntero del mouse se mueve dentro de una celda. (Invalida a DataGridViewCell..::.OnMouseMove(DataGridViewCellMouseEventArgs)). | .gif) | OnMouseUp | Se le llama cuando el usuario suelta un botón del mouse mientras el puntero está en una celda. (Se hereda de DataGridViewCell). | .gif) | Paint | Dibuja la celda DataGridViewComboBoxCell actual. (Invalida a DataGridViewCell..::.Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)). | .gif) | PaintBorder | Dibuja el borde del control DataGridViewCell actual. (Se hereda de DataGridViewCell). | .gif) | PaintErrorIcon | Dibuja el icono de error del control DataGridViewCell actual. (Se hereda de DataGridViewCell). | .gif) | ParseFormattedValue | Convierte un valor con formato de presentación en un valor de celda real. (Invalida a DataGridViewCell..::.ParseFormattedValue(Object, DataGridViewCellStyle, TypeConverter, TypeConverter)). | .gif) | PositionEditingControl | Establece la ubicación y tamaño del control de edición que hospeda una celda del control DataGridView. (Se hereda de DataGridViewCell). | .gif) | PositionEditingPanel | Establece la ubicación y tamaño del panel de edición que hospeda la celda y devuelve los límites normales del control de edición dentro del panel de edición. (Se hereda de DataGridViewCell). | .gif) | RaiseCellClick | Provoca el evento DataGridView..::.CellClick. (Se hereda de DataGridViewElement). | .gif) | RaiseCellContentClick | Genera el evento DataGridView..::.CellContentClick. (Se hereda de DataGridViewElement). | .gif) | RaiseCellContentDoubleClick | Genera el evento DataGridView..::.CellContentDoubleClick. (Se hereda de DataGridViewElement). | .gif) | RaiseCellValueChanged | Genera el evento DataGridView..::.CellValueChanged. (Se hereda de DataGridViewElement). | .gif) | RaiseDataError | Genera el evento DataGridView..::.DataError. (Se hereda de DataGridViewElement). | .gif) | RaiseMouseWheel | Provoca el evento Control..::.MouseWheel. (Se hereda de DataGridViewElement). | .gif) | SetValue | Establece el valor de la celda. (Se hereda de DataGridViewCell). | .gif) | ToString | Devuelve una cadena que describe el objeto actual. (Invalida a DataGridViewCell..::.ToString()()()). | Arriba

Comentarios
La clase DataGridViewComboBoxCell es un tipo especializado de DataGridViewCell utilizado para mostrar un control de cuadro combinado que es un campo de edición combinado con un campo de selección de lista. La clase DataGridViewComboBoxCell seleccionada actualmente contiene un control DataGridViewComboBoxEditingControl en el que el usuario puede cambiar el valor de la celda, presuponiendo que la propiedad ReadOnly de la celda está establecida en false. A diferencia del control ComboBox, DataGridViewComboBoxCell no tiene las propiedades SelectedIndex ni SelectedValue. En su lugar, cuando se selecciona un valor de una lista desplegable, se establece la propiedad Value de celda. DataGridViewComboBoxColumn corresponde al tipo de columna especializado para contener celdas de este tipo. De manera predeterminada, la propiedad DataGridViewComboBoxColumn..::.CellTemplate se inicializa con una nueva DataGridViewComboBoxCell. Para modelar las celdas dentro de una columna como un control DataGridViewComboBoxCell existente, establezca la propiedad CellTemplate de la columna en la celda para usar como modelo. Las propiedades de la columna relacionadas con celdas actúan como contenedores para las propiedades con nombres similares de la celda de plantilla. Al cambiar los valores de propiedad de la celda de plantilla sólo se verán afectadas las celdas que estén basadas en la plantilla y se hayan agregado después del cambio. Al cambiar los valores de propiedad relacionados con las celdas de la columna, sin embargo, se actualizará la celda de la plantilla y también todas las demás celdas de la columna, actualizando su presentación si es necesario. Normalmente trabajará con el tipo DataGridViewComboBoxColumn, a menos que desee reemplazar valores de columna para celdas específicas. Las instrucciones descritas en el tema de información general sobre la clase DataGridViewComboBoxColumn para rellenar la lista desplegable se aplican a instancias de celda y de columna. Notas para los herederosCuando derive del control DataGridViewComboBoxCell y agregue nuevas propiedades a la clase derivada, asegúrese de reemplazar el método Clone para copiar las nuevas propiedades durante las operaciones de clonación. También debe llamar al método Clone de la clase base para que las propiedades de la clase base se copien a la nueva celda.

Ejemplos
En el ejemplo de código siguiente se muestra la clase DataGridViewComboBoxColumn, que utiliza la clase DataGridViewComboBoxCell. Puede establecer las propiedades DataSource, ValueMember y DisplayMember de la celda del mismo modo que se establecen las propiedades de columna correspondientes en este ejemplo. Este ejemplo forma parte de un ejemplo más extenso que está disponible en el tema de información general sobre la clase DataGridViewComboBoxColumn.
Private Function CreateComboBoxColumn() _
As DataGridViewComboBoxColumn
Dim column As New DataGridViewComboBoxColumn()
With column
.DataPropertyName = ColumnName.TitleOfCourtesy.ToString()
.HeaderText = ColumnName.TitleOfCourtesy.ToString()
.DropDownWidth = 160
.Width = 90
.MaxDropDownItems = 3
.FlatStyle = FlatStyle.Flat
End With
Return column
End Function
Private Sub SetAlternateChoicesUsingDataSource( _
ByVal comboboxColumn As DataGridViewComboBoxColumn)
With comboboxColumn
.DataSource = RetrieveAlternativeTitles()
.ValueMember = ColumnName.TitleOfCourtesy.ToString()
.DisplayMember = .ValueMember
End With
End Sub
Private Function RetrieveAlternativeTitles() As DataTable
Return Populate( _
"SELECT distinct TitleOfCourtesy FROM Employees")
End Function
Private connectionString As String = _
"Integrated Security=SSPI;Persist Security Info=False;" _
& "Initial Catalog=Northwind;Data Source=localhost"
Private Function Populate(ByVal sqlCommand As String) As DataTable
Dim northwindConnection As New SqlConnection(connectionString)
northwindConnection.Open()
Dim command As New SqlCommand(sqlCommand, _
northwindConnection)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = command
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
adapter.Fill(table)
Return table
End Function
' Using an enum provides some abstraction between column index
' and column name along with compile time checking, and gives
' a handy place to store the column names.
Enum ColumnName
EmployeeId
LastName
FirstName
Title
TitleOfCourtesy
BirthDate
HireDate
Address
City
Region
PostalCode
Country
HomePhone
Extension
Photo
Notes
ReportsTo
PhotoPath
OutOfOffice
End Enum
private DataGridViewComboBoxColumn CreateComboBoxColumn()
{
DataGridViewComboBoxColumn column =
new DataGridViewComboBoxColumn();
{
column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
column.DropDownWidth = 160;
column.Width = 90;
column.MaxDropDownItems = 3;
column.FlatStyle = FlatStyle.Flat;
}
return column;
}
private void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn comboboxColumn)
{
{
comboboxColumn.DataSource = RetrieveAlternativeTitles();
comboboxColumn.ValueMember = ColumnName.TitleOfCourtesy.ToString();
comboboxColumn.DisplayMember = comboboxColumn.ValueMember;
}
}
private DataTable RetrieveAlternativeTitles()
{
return Populate("SELECT distinct TitleOfCourtesy FROM Employees");
}
string connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
private DataTable Populate(string sqlCommand)
{
SqlConnection northwindConnection = new SqlConnection(connectionString);
northwindConnection.Open();
SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
return table;
}
// Using an enum provides some abstraction between column index
// and column name along with compile time checking, and gives
// a handy place to store the column names.
enum ColumnName
{
EmployeeId,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath,
OutOfOffice
};
private:
DataGridViewComboBoxColumn^ CreateComboBoxColumn()
{
DataGridViewComboBoxColumn^ column =
gcnew DataGridViewComboBoxColumn();
{
column->DataPropertyName = ColumnName::TitleOfCourtesy.ToString();
column->HeaderText = ColumnName::TitleOfCourtesy.ToString();
column->DropDownWidth = 160;
column->Width = 90;
column->MaxDropDownItems = 3;
column->FlatStyle = FlatStyle::Flat;
}
return column;
}
private:
void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn^ comboboxColumn)
{
{
comboboxColumn->DataSource = RetrieveAlternativeTitles();
comboboxColumn->ValueMember = ColumnName::TitleOfCourtesy.ToString();
comboboxColumn->DisplayMember = comboboxColumn->ValueMember;
}
}
private:
DataTable^ RetrieveAlternativeTitles()
{
return Populate("SELECT distinct TitleOfCourtesy FROM Employees");
}
String^ connectionString;
private:
DataTable^ Populate(String^ sqlCommand)
{
SqlConnection^ northwindConnection = gcnew SqlConnection(connectionString);
northwindConnection->Open();
SqlCommand^ command = gcnew SqlCommand(sqlCommand, northwindConnection);
SqlDataAdapter^ adapter = gcnew SqlDataAdapter();
adapter->SelectCommand = command;
DataTable^ table = gcnew DataTable();
adapter->Fill(table);
return table;
}
// Using an enum provides some abstraction between column index
// and column name along with compile time checking, and gives
// a handy place to store the column names.
enum class ColumnName
{
EmployeeID,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath,
OutOfOffice
};

Información de versión
.NET FrameworkCompatible con: 4, 3.5, 3.0, 2.0 .NET Framework Client ProfileCompatible con: 4, 3.5 SP1

Plataformas
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Seguridad para subprocesos
Todos los miembros static ( Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Vea también
|