DataGridViewRowPostPaintEventArgs.State 屬性

定義

取得目前 DataGridViewRow 的狀態。

public:
 property System::Windows::Forms::DataGridViewElementStates State { System::Windows::Forms::DataGridViewElementStates get(); };
public System.Windows.Forms.DataGridViewElementStates State { get; }
member this.State : System.Windows.Forms.DataGridViewElementStates
Public ReadOnly Property State As DataGridViewElementStates

屬性值

DataGridViewElementStates 值的位元組合,指定資料列的狀態。

範例

下列程式碼範例示範如何使用 State 屬性來判斷是否選取目前的資料列。 變數 的 eDataGridViewRowPostPaintEventArgs 別為 。 此程式碼範例是如何:自訂 DataGridView 控制項中 Windows Forms資料列外觀中提供之較大範例的一部分。

// Determine the foreground color.
if ((e.State & DataGridViewElementStates.Selected) ==
    DataGridViewElementStates.Selected)
{
    forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
}
else
{
    forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
}
' Determine the foreground color.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
Else
    forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
End If

備註

這個屬性可用來判斷資料列是否凍結、唯讀或選取其他狀態。

適用於

另請參閱