.NET Framework Class Library DataGridViewRow Class

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

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

Constructors
|
| Name | Description |
|---|
.gif) | DataGridViewRow | Initializes a new instance of the DataGridViewRow class without using a template. | Top

Properties

Methods

Remarks
The DataGridViewRow class represents a row in a DataGridView control. You can retrieve rows through the Rows and SelectedRows collections of the control. Unlike a DataGridViewColumn, a DataGridViewRow physically contains a collection of all of the cells in that row. You can access this collection through the Cells property. The DataGridViewRow class is used to access the individual cell elements, as well as to adjust the appearance and behavior of the row user interface (UI), such as height and cell style. Typically, you will want all rows or most rows in the control to share the same characteristics. To set cell styles for all rows in the control, set the properties of the object returned by the DataGridView..::.RowsDefaultCellStyle property. To set styles for alternating rows, use the DataGridView..::.AlternatingRowsDefaultCellStyle property. For more information about cell styles, see Cell Styles in the Windows Forms DataGridView Control. You can also use the DataGridView..::.RowTemplate property to define a row that will be used as a basis for all rows added to the control. The DataGridView control will share DataGridViewRow objects across multiple data rows whenever possible to avoid performance penalties. Unless you are working with large amounts of data and experiencing performance issues, you can typically ignore row sharing. A shared row is indicated by an Index property value of -1. Some members of the DataGridViewRow class cannot be used with shared rows, but you can unshare a row by accessing it through the DataGridViewRowCollection..::.Item property. Rows can also become unshared in other ways. To access a row without unsharing it, use the DataGridViewRowCollection..::.SharedRow method. When working with large amounts of data, you should be aware of how rows are shared and unshared to avoid performance penalties. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control. Notes to InheritorsWhen you derive from DataGridViewRow 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 illustrates the use of this type. This example is part of a larger example available in How to: Manipulate Rows in the Windows Forms DataGridView Control.
' Set row labels.
Private Sub Button6_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button6.Click
Dim rowNumber As Integer = 1
For Each row As DataGridViewRow In dataGridView.Rows
If row.IsNewRow Then Continue For
row.HeaderCell.Value = "Row " & rowNumber
rowNumber = rowNumber + 1
Next
dataGridView.AutoResizeRowHeadersWidth( _
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
End Sub
// Set row labels.
private void Button6_Click(object sender, System.EventArgs e)
{
int rowNumber = 1;
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (row.IsNewRow) continue;
row.HeaderCell.Value = "Row " + rowNumber;
rowNumber = rowNumber + 1;
}
dataGridView.AutoResizeRowHeadersWidth(
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
}
// Set row labels.
void Button6_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int rowNumber = 1;
System::Collections::IEnumerator^ myEnum = safe_cast<System::Collections::IEnumerable^>(dataGridView->Rows)->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewRow^ row = safe_cast<DataGridViewRow^>(myEnum->Current);
if ( row->IsNewRow )
continue;
row->HeaderCell->Value = String::Format( L"Row {0}", rowNumber );
rowNumber = rowNumber + 1;
}
dataGridView->AutoResizeRowHeadersWidth( DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders );
}

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 DataGridViewRow (Clase)

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

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

Constructores
|
| Nombre | Descripción |
|---|
.gif) | DataGridViewRow | Inicializa una nueva instancia de la clase DataGridViewRow sin utilizar una plantilla. | Arriba

Propiedades

Métodos

Comentarios
La clase DataGridViewRow representa una fila de un control DataGridView. Puede recuperar filas a través de las colecciones de Rows y SelectedRows del control. A diferencia de DataGridViewColumn, DataGridViewRow contiene físicamente una colección de todas las celdas de esa fila. Se puede obtener acceso a esta colección mediante la propiedad Cells. La clase DataGridViewRow se utiliza para obtener acceso a cada elemento de celda, así como para ajustar la apariencia y el comportamiento de la interfaz de usuario (UI) de la fila, como el alto y el estilo de celda. Normalmente, le interesará que todas las filas del control, o la mayoría de ellas, compartan las mismas características. Para establecer los estilos de celda para todas las filas del control, establezca las propiedades del objeto que devuelve la propiedad DataGridView..::.RowsDefaultCellStyle. Para establecer los estilos de las filas alternas, utilice la propiedad DataGridView..::.AlternatingRowsDefaultCellStyle. Para obtener más información sobre los estilos de celda, vea Estilos de celda en el control DataGridView de formularios Windows Forms También se puede utilizar la propiedad DataGridView..::.RowTemplate para definir una fila que sirva de base para todas las filas que se agreguen al control. Para evitar reducciones del rendimiento y siempre que sea posible, el control DataGridView compartirá objetos DataGridViewRow por varias filas de datos. Por lo común podrá omitir el uso compartido de filas, salvo cuando esté trabajando con cantidades grandes de datos y experimente problemas de rendimiento. Una fila compartida viene indicada por un valor -1 en la propiedad Index. Algunos miembros de la clase DataGridViewRow no se pueden utilizar con filas compartidas, pero se puede hacer que una fila deje de estar compartida obteniendo acceso a ella a través de la propiedad DataGridViewRowCollection..::.Item. También hay otras formas de hacer que las filas dejen de estar compartidas. Para obtener acceso a una fila sin que deje de estar compartida, utilice el método DataGridViewRowCollection..::.SharedRow. Cuando trabaje con grandes cantidades de datos, tenga presente cómo están compartidas o no las filas para evitar reducciones del rendimiento. Para obtener más información, vea Procedimientos recomendados para ajustar la escala del control DataGridView en formularios Windows Forms. Notas para los herederosCuando derive de DataGridViewRow 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 en la nueva celda.

Ejemplos
En el ejemplo de código siguiente se muestra el uso de este tipo. Este ejemplo forma parte de un ejemplo más extenso proporcionado en Cómo: Manipular filas en el control DataGridView de formularios Windows Forms.
' Set row labels.
Private Sub Button6_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button6.Click
Dim rowNumber As Integer = 1
For Each row As DataGridViewRow In dataGridView.Rows
If row.IsNewRow Then Continue For
row.HeaderCell.Value = "Row " & rowNumber
rowNumber = rowNumber + 1
Next
dataGridView.AutoResizeRowHeadersWidth( _
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
End Sub
// Set row labels.
private void Button6_Click(object sender, System.EventArgs e)
{
int rowNumber = 1;
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (row.IsNewRow) continue;
row.HeaderCell.Value = "Row " + rowNumber;
rowNumber = rowNumber + 1;
}
dataGridView.AutoResizeRowHeadersWidth(
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
}
// Set row labels.
void Button6_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int rowNumber = 1;
System::Collections::IEnumerator^ myEnum = safe_cast<System::Collections::IEnumerable^>(dataGridView->Rows)->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewRow^ row = safe_cast<DataGridViewRow^>(myEnum->Current);
if ( row->IsNewRow )
continue;
row->HeaderCell->Value = String::Format( L"Row {0}", rowNumber );
rowNumber = rowNumber + 1;
}
dataGridView->AutoResizeRowHeadersWidth( DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders );
}

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
|