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 Forms 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

備註

類別代表DataGridView控制項中的資料列。 DataGridViewRowThe 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 Forms 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.

控制項會盡可能在DataGridViewRow多個資料列之間共用物件, 以避免效能受到負面影響。 DataGridViewThe 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. 共用資料列會以-1 Index的屬性值表示。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 Form 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 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。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)

在指定的界限四周繪製焦點矩形 (Focus Rectangle)。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 的淺層複本 (Shallow Copy)。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()

取得描述資料列之人們可讀取的 (Human-Readable) 字串。Gets a human-readable string that describes the row.

適用於

另請參閱