DataGridViewRow DataGridViewRow DataGridViewRow DataGridViewRow Class

Definition

Represents a row in a DataGridView control.

public ref class DataGridViewRow : System::Windows::Forms::DataGridViewBand
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.DataGridViewRowConverter))]
public class DataGridViewRow : System.Windows.Forms.DataGridViewBand
type DataGridViewRow = class
    inherit DataGridViewBand
Public Class DataGridViewRow
Inherits DataGridViewBand
Inheritance
Attributes

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.
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 );
}


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

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[Int32] 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 Inheritors

When 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.

Constructors

DataGridViewRow() DataGridViewRow() DataGridViewRow() DataGridViewRow()

Initializes a new instance of the DataGridViewRow class without using a template.

Properties

AccessibilityObject AccessibilityObject AccessibilityObject AccessibilityObject

Gets the DataGridViewRow.DataGridViewRowAccessibleObject assigned to the DataGridViewRow.

Cells Cells Cells Cells

Gets the collection of cells that populate the row.

ContextMenuStrip ContextMenuStrip ContextMenuStrip ContextMenuStrip

Gets or sets the shortcut menu for the row.

DataBoundItem DataBoundItem DataBoundItem DataBoundItem

Gets the data-bound object that populated the row.

DataGridView DataGridView DataGridView DataGridView

Gets the DataGridView control associated with this element.

(Inherited from DataGridViewElement)
DefaultCellStyle DefaultCellStyle DefaultCellStyle DefaultCellStyle

Gets or sets the default styles for the row, which are used to render cells in the row unless the styles are overridden.

DefaultHeaderCellType DefaultHeaderCellType DefaultHeaderCellType DefaultHeaderCellType

Gets or sets the run-time type of the default header cell.

(Inherited from DataGridViewBand)
Displayed Displayed Displayed Displayed

Gets a value indicating whether this row is displayed on the screen.

DividerHeight DividerHeight DividerHeight DividerHeight

Gets or sets the height, in pixels, of the row divider.

ErrorText ErrorText ErrorText ErrorText

Gets or sets the error message text for row-level errors.

Frozen Frozen Frozen Frozen

Gets or sets a value indicating whether the row is frozen.

HasDefaultCellStyle HasDefaultCellStyle HasDefaultCellStyle HasDefaultCellStyle

Gets a value indicating whether the DefaultCellStyle property has been set.

(Inherited from DataGridViewBand)
HeaderCell HeaderCell HeaderCell HeaderCell

Gets or sets the row's header cell.

HeaderCellCore HeaderCellCore HeaderCellCore HeaderCellCore

Gets or sets the header cell of the DataGridViewBand.

(Inherited from DataGridViewBand)
Height Height Height Height

Gets or sets the current height of the row.

Index Index Index Index

Gets the relative position of the band within the DataGridView control.

(Inherited from DataGridViewBand)
InheritedStyle InheritedStyle InheritedStyle InheritedStyle

Gets the cell style in effect for the row.

IsNewRow IsNewRow IsNewRow IsNewRow

Gets a value indicating whether the row is the row for new records.

IsRow IsRow IsRow IsRow

Gets a value indicating whether the band represents a row.

(Inherited from DataGridViewBand)
MinimumHeight MinimumHeight MinimumHeight MinimumHeight

Gets or sets the minimum height of the row.

ReadOnly ReadOnly ReadOnly ReadOnly

Gets or sets a value indicating whether the row is read-only.

Resizable Resizable Resizable Resizable

Gets or sets a value indicating whether users can resize the row or indicating that the behavior is inherited from the AllowUserToResizeRows property.

Selected Selected Selected Selected

Gets or sets a value indicating whether the row is selected.

State State State State

Gets the current state of the row.

Tag Tag Tag Tag

Gets or sets the object that contains data to associate with the band.

(Inherited from DataGridViewBand)
Visible Visible Visible Visible

Gets or sets a value indicating whether the row is visible.

Methods

AdjustRowHeaderBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean) AdjustRowHeaderBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean) AdjustRowHeaderBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean) AdjustRowHeaderBorderStyle(DataGridViewAdvancedBorderStyle, DataGridViewAdvancedBorderStyle, Boolean, Boolean, Boolean, Boolean)

Modifies an input row header border style according to the specified criteria.

Clone() Clone() Clone() Clone()

Creates an exact copy of this row.

CreateAccessibilityInstance() CreateAccessibilityInstance() CreateAccessibilityInstance() CreateAccessibilityInstance()

Creates a new accessible object for the DataGridViewRow.

CreateCells(DataGridView) CreateCells(DataGridView) CreateCells(DataGridView) CreateCells(DataGridView)

Clears the existing cells and sets their template according to the supplied DataGridView template.

CreateCells(DataGridView, Object[]) CreateCells(DataGridView, Object[]) CreateCells(DataGridView, Object[]) CreateCells(DataGridView, Object[])

Clears the existing cells and sets their template and values.

CreateCellsInstance() CreateCellsInstance() CreateCellsInstance() CreateCellsInstance()

Constructs a new collection of cells based on this row.

Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the DataGridViewBand.

(Inherited from DataGridViewBand)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the DataGridViewBand and optionally releases the managed resources.

(Inherited from DataGridViewBand)
DrawFocus(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, DataGridViewCellStyle, Boolean) DrawFocus(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, DataGridViewCellStyle, Boolean) DrawFocus(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, DataGridViewCellStyle, Boolean) DrawFocus(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, DataGridViewCellStyle, Boolean)

Draws a focus rectangle around the specified bounds.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetContextMenuStrip(Int32) GetContextMenuStrip(Int32) GetContextMenuStrip(Int32) GetContextMenuStrip(Int32)

Gets the shortcut menu for the row.

GetErrorText(Int32) GetErrorText(Int32) GetErrorText(Int32) GetErrorText(Int32)

Gets the error text for the row at the specified index.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetPreferredHeight(Int32, DataGridViewAutoSizeRowMode, Boolean) GetPreferredHeight(Int32, DataGridViewAutoSizeRowMode, Boolean) GetPreferredHeight(Int32, DataGridViewAutoSizeRowMode, Boolean) GetPreferredHeight(Int32, DataGridViewAutoSizeRowMode, Boolean)

Calculates the ideal height of the specified row based on the specified criteria.

GetState(Int32) GetState(Int32) GetState(Int32) GetState(Int32)

Returns a value indicating the current state of the row.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnDataGridViewChanged() OnDataGridViewChanged() OnDataGridViewChanged() OnDataGridViewChanged()

Called when the band is associated with a different DataGridView.

(Inherited from DataGridViewBand)
Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean) Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean) Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean) Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean)

Paints the current row.

PaintCells(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts) PaintCells(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts) PaintCells(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts) PaintCells(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts)

Paints the cells in the current row.

PaintHeader(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts) PaintHeader(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts) PaintHeader(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts) PaintHeader(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean, DataGridViewPaintParts)

Paints the header cell of the current row.

RaiseCellClick(DataGridViewCellEventArgs) RaiseCellClick(DataGridViewCellEventArgs) RaiseCellClick(DataGridViewCellEventArgs) RaiseCellClick(DataGridViewCellEventArgs)

Raises the CellClick event.

(Inherited from DataGridViewElement)
RaiseCellContentClick(DataGridViewCellEventArgs) RaiseCellContentClick(DataGridViewCellEventArgs) RaiseCellContentClick(DataGridViewCellEventArgs) RaiseCellContentClick(DataGridViewCellEventArgs)

Raises the CellContentClick event.

(Inherited from DataGridViewElement)
RaiseCellContentDoubleClick(DataGridViewCellEventArgs) RaiseCellContentDoubleClick(DataGridViewCellEventArgs) RaiseCellContentDoubleClick(DataGridViewCellEventArgs) RaiseCellContentDoubleClick(DataGridViewCellEventArgs)

Raises the CellContentDoubleClick event.

(Inherited from DataGridViewElement)
RaiseCellValueChanged(DataGridViewCellEventArgs) RaiseCellValueChanged(DataGridViewCellEventArgs) RaiseCellValueChanged(DataGridViewCellEventArgs) RaiseCellValueChanged(DataGridViewCellEventArgs)

Raises the CellValueChanged event.

(Inherited from DataGridViewElement)
RaiseDataError(DataGridViewDataErrorEventArgs) RaiseDataError(DataGridViewDataErrorEventArgs) RaiseDataError(DataGridViewDataErrorEventArgs) RaiseDataError(DataGridViewDataErrorEventArgs)

Raises the DataError event.

(Inherited from DataGridViewElement)
RaiseMouseWheel(MouseEventArgs) RaiseMouseWheel(MouseEventArgs) RaiseMouseWheel(MouseEventArgs) RaiseMouseWheel(MouseEventArgs)

Raises the MouseWheel event.

(Inherited from DataGridViewElement)
SetValues(Object[]) SetValues(Object[]) SetValues(Object[]) SetValues(Object[])

Sets the values of the row's cells.

ToString() ToString() ToString() ToString()

Gets a human-readable string that describes the row.

Applies to

See also