DataGridViewRow 类

定义

表示 DataGridView 控件中的行。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
继承
属性

示例

下面的代码示例演示如何使用此类型。The following code example illustrates the use of this type. 此示例摘自 How 中提供的更大示例的一部分:操作 Windows 窗体 DataGridView 控件中的行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

注解

DataGridViewRow 类表示 DataGridView 控件中的一行。The DataGridViewRow class represents a row in a DataGridView control. 您可以通过控件的 RowsSelectedRows 集合来检索行。You can retrieve rows through the Rows and SelectedRows collections of the control.

DataGridViewColumn不同,DataGridViewRow 物理上包含该行中所有单元格的集合。Unlike a DataGridViewColumn, a DataGridViewRow physically contains a collection of all of the cells in that row. 可以通过 Cells 属性访问此集合。You can access this collection through the Cells property.

DataGridViewRow 类用于访问单个单元格元素,并用于调整行用户界面(UI)的外观和行为,例如高度和单元格样式。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. 若要设置控件中所有行的单元格样式,请设置 DataGridView.RowsDefaultCellStyle 属性返回的对象的属性。To set cell styles for all rows in the control, set the properties of the object returned by the DataGridView.RowsDefaultCellStyle property. 若要为交替行设置样式,请使用 DataGridView.AlternatingRowsDefaultCellStyle 属性。To set styles for alternating rows, use the DataGridView.AlternatingRowsDefaultCellStyle property. 有关单元格样式的详细信息,请参阅Windows 窗体 DataGridView 控件中的单元格样式For more information about cell styles, see Cell Styles in the Windows Forms DataGridView Control. 你还可以使用 DataGridView.RowTemplate 属性来定义将用作添加到控件的所有行的基础的行。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.

DataGridView 控件将尽可能跨多个数据行共享 DataGridViewRow 对象,以避免性能下降。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. 共享行由 Index 属性值-1 表示。A shared row is indicated by an Index property value of -1. DataGridViewRow 类的某些成员不能用于共享行,但您可以通过 DataGridViewRowCollection.Item[Int32] 属性访问行来取消共享行。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. 若要在不取消共享行的情况下访问该行,请使用 DataGridViewRowCollection.SharedRow 方法。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. 有关详细信息,请参阅 缩放 Windows 窗体 DataGridView 控件的最佳做法For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

继承者说明

当从 DataGridViewRow 派生并向派生类添加新属性时,请确保重写 Clone() 方法,以便在克隆操作过程中复制新属性。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. 还应调用基类的 Clone() 方法,以便将基类的属性复制到新单元。You should also call the base class's Clone() method so that the properties of the base class are copied to the new cell.

构造函数

DataGridViewRow()

在不使用模板的情况下初始化 DataGridViewRow 类的新实例。Initializes a new instance of the DataGridViewRow class without using a template.

属性

AccessibilityObject

获取分配给 DataGridViewRow.DataGridViewRowAccessibleObjectDataGridViewRowGets the DataGridViewRow.DataGridViewRowAccessibleObject assigned to the DataGridViewRow.

Cells

获取用于填充行的单元格集合。Gets the collection of cells that populate the row.

ContextMenuStrip

获取或设置行的快捷菜单。Gets or sets the shortcut menu for the row.

DataBoundItem

获取用于填充行的数据绑定对象。Gets the data-bound object that populated the row.

DataGridView

获取与此元素关联的 DataGridView 控件。Gets the DataGridView control associated with this element.

(继承自 DataGridViewElement)
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

获取或设置默认标题单元格的运行时类型。Gets or sets the run-time type of the default header cell.

(继承自 DataGridViewBand)
Displayed

获取一个值,指示此行是否显示在屏幕上。Gets a value indicating whether this row is displayed on the screen.

DividerHeight

获取或设置行分隔符的高度(以像素为单位)。Gets or sets the height, in pixels, of the row divider.

ErrorText

获取或设置行级别错误的错误消息文本。Gets or sets the error message text for row-level errors.

Frozen

获取或设置一个指示行是否已被冻结的值。Gets or sets a value indicating whether the row is frozen.

HasDefaultCellStyle

获取指示是否已设置 DefaultCellStyle 属性的值。Gets a value indicating whether the DefaultCellStyle property has been set.

(继承自 DataGridViewBand)
HeaderCell

获取或设置行的标头单元格。Gets or sets the row's header cell.

HeaderCellCore

获取或设置 DataGridViewBand 的标题单元格。Gets or sets the header cell of the DataGridViewBand.

(继承自 DataGridViewBand)
Height

获取或设置行的当前高度。Gets or sets the current height of the row.

Index

获取带区在 DataGridView 控件中的相对位置。Gets the relative position of the band within the DataGridView control.

(继承自 DataGridViewBand)
InheritedStyle

获取行中生效的单元格样式。Gets the cell style in effect for the row.

IsNewRow

获取一个值,指示行是否为用于新纪录的行。Gets a value indicating whether the row is the row for new records.

IsRow

获取一个值,该值指示带区是否表示一个行。Gets a value indicating whether the band represents a row.

(继承自 DataGridViewBand)
MinimumHeight

获取或设置行的最小高度。Gets or sets the minimum height of the row.

ReadOnly

获取或设置一个值,指示行是否为只读。Gets or sets a value indicating whether the row is read-only.

Resizable

获取或设置一个值,该值指示用户是否可以调整行大小,或指示该行为继承自 AllowUserToResizeRows 属性。Gets or sets a value indicating whether users can resize the row or indicating that the behavior is inherited from the AllowUserToResizeRows property.

Selected

获取或设置一个指示行是否已被选定的值。Gets or sets a value indicating whether the row is selected.

State

获取行的当前状态。Gets the current state of the row.

Tag

获取或设置包含与带区关联的数据的对象。Gets or sets the object that contains data to associate with the band.

(继承自 DataGridViewBand)
Visible

获取或设置一个指示行是否可见的值。Gets or sets a value indicating whether the row is visible.

方法

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

根据指定的条件修改输入行标头的边框样式。Modifies an input row header border style according to the specified criteria.

Clone()

创建此行的精确副本。Creates an exact copy of this row.

CreateAccessibilityInstance()

DataGridViewRow 创建一个新的可访问对象。Creates a new accessible object for the DataGridViewRow.

CreateCells(DataGridView)

根据所提供的 DataGridView 模板清除现有单元格并设置它们的模板。Clears the existing cells and sets their template according to the supplied DataGridView template.

CreateCells(DataGridView, Object[])

清除现有单元格并设置其模板和值。Clears the existing cells and sets their template and values.

CreateCellsInstance()

根据此行构造新的单元格集合。Constructs a new collection of cells based on this row.

Dispose()

释放由 DataGridViewBand 使用的所有资源。Releases all resources used by the DataGridViewBand.

(继承自 DataGridViewBand)
Dispose(Boolean)

释放由 DataGridViewBand 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the DataGridViewBand and optionally releases the managed resources.

(继承自 DataGridViewBand)
DrawFocus(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, DataGridViewCellStyle, Boolean)

围绕指定边界绘制聚焦框。Draws a focus rectangle around the specified bounds.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetContextMenuStrip(Int32)

获取行的快捷菜单。Gets the shortcut menu for the row.

GetErrorText(Int32)

获取指定索引处的行的错误文本。Gets the error text for the row at the specified index.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetPreferredHeight(Int32, DataGridViewAutoSizeRowMode, Boolean)

根据指定的条件计算指定行的理想高度。Calculates the ideal height of the specified row based on the specified criteria.

GetState(Int32)

返回一个指示行的当前状态的值。Returns a value indicating the current state of the row.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnDataGridViewChanged()

当带区与其他 DataGridView 关联时调用。Called when the band is associated with a different DataGridView.

(继承自 DataGridViewBand)
Paint(Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, Boolean, Boolean)

绘制当前行。Paints the current row.

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)

绘制当前行的标头单元格。Paints the header cell of the current row.

RaiseCellClick(DataGridViewCellEventArgs)

引发 CellClick 事件。Raises the CellClick event.

(继承自 DataGridViewElement)
RaiseCellContentClick(DataGridViewCellEventArgs)

引发 CellContentClick 事件。Raises the CellContentClick event.

(继承自 DataGridViewElement)
RaiseCellContentDoubleClick(DataGridViewCellEventArgs)

引发 CellContentDoubleClick 事件。Raises the CellContentDoubleClick event.

(继承自 DataGridViewElement)
RaiseCellValueChanged(DataGridViewCellEventArgs)

引发 CellValueChanged 事件。Raises the CellValueChanged event.

(继承自 DataGridViewElement)
RaiseDataError(DataGridViewDataErrorEventArgs)

引发 DataError 事件。Raises the DataError event.

(继承自 DataGridViewElement)
RaiseMouseWheel(MouseEventArgs)

引发 MouseWheel 事件。Raises the MouseWheel event.

(继承自 DataGridViewElement)
SetValues(Object[])

设置行的单元格的值。Sets the values of the row's cells.

ToString()

获取用于描述行的用户可以理解的字符串。Gets a human-readable string that describes the row.

适用于

另请参阅