DataGridViewRow DataGridViewRow DataGridViewRow DataGridViewRow Class

定义

表示 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. 此示例摘自一个更大的示例中提供如何:操作 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.

与不同DataGridViewColumnDataGridViewRow以物理方式包含所有的行中单元格的集合。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() DataGridViewRow() DataGridViewRow()

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

属性

AccessibilityObject AccessibilityObject AccessibilityObject AccessibilityObject

获取分配给 DataGridViewRow.DataGridViewRowAccessibleObjectDataGridViewRowGets 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

获取与此元素关联的 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

获取指示是否已设置 DefaultCellStyle 属性的值。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

获取或设置 DataGridViewBand 的标题单元格。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

获取带区在 DataGridView 控件中的相对位置。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

获取或设置一个值,该值指示用户是否可以调整行大小,或指示该行为继承自 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 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.

方法

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

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

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

根据所提供的 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()

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

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

释放由 DataGridViewBand 占用的非托管资源,还可以另外再释放托管资源。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()

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

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

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

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

当带区与其他 DataGridView 关联时调用。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)

引发 CellClick 事件。Raises the CellClick event.

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

引发 CellContentClick 事件。Raises the CellContentClick event.

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

引发 CellContentDoubleClick 事件。Raises the CellContentDoubleClick event.

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

引发 CellValueChanged 事件。Raises the CellValueChanged event.

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

引发 DataError 事件。Raises the DataError event.

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

引发 MouseWheel 事件。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.

适用于

另请参阅