共用方式為


DataGridViewRow.Selected 屬性

定義

取得或設定值,指出是否已選取資料列。

public:
 virtual property bool Selected { bool get(); void set(bool value); };
public override bool Selected { get; set; }
member this.Selected : bool with get, set
Public Overrides Property Selected As Boolean

屬性值

如果資料列已選取則為 true,否則為 false

例外狀況

資料列位於 DataGridView 控制項中而且是一個共用資料列。

範例

下列程式代碼範例說明如何使用這個屬性。

void dataGridView1_ColumnHeaderMouseClick(
    object sender, DataGridViewCellMouseEventArgs e)
{
    this.dataGridView1.SelectionMode =
        DataGridViewSelectionMode.ColumnHeaderSelect;
    this.dataGridView1.Columns[e.ColumnIndex].HeaderCell
        .SortGlyphDirection = SortOrder.None;
    this.dataGridView1.Columns[e.ColumnIndex].Selected = true;
}

void dataGridView1_RowHeaderMouseClick(
    object sender, DataGridViewCellMouseEventArgs e)
{
    this.dataGridView1.SelectionMode =
        DataGridViewSelectionMode.RowHeaderSelect;
    this.dataGridView1.Rows[e.RowIndex].Selected = true;
}
Private Sub dataGridView1_ColumnHeaderMouseClick( _
    ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) _
    Handles dataGridView1.ColumnHeaderMouseClick

    Me.dataGridView1.SelectionMode = _
        DataGridViewSelectionMode.ColumnHeaderSelect
    Me.dataGridView1.Columns(e.ColumnIndex).HeaderCell _
        .SortGlyphDirection = SortOrder.None
    Me.dataGridView1.Columns(e.ColumnIndex).Selected = True

End Sub

Private Sub dataGridView1_RowHeaderMouseClick( _
    ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) _
    Handles dataGridView1.RowHeaderMouseClick

    Me.dataGridView1.SelectionMode = _
        DataGridViewSelectionMode.RowHeaderSelect
    Me.dataGridView1.Rows(e.RowIndex).Selected = True

End Sub

備註

您無法將此屬性與共享資料列搭配使用。 如需共用數據列的詳細資訊,請參閱調整 Windows Forms DataGridView 控件的最佳做法

適用於

另請參閱