DataGridView.ClearSelection 方法

定義

取消選取目前已選取的儲存格。

多載

ClearSelection(Int32, Int32, Boolean)

取消選取目前已選取的所有儲存格 (除了指示的儲存格以外),並選擇性地確定所指示的儲存格已選取。

ClearSelection()

取消選取所有選取的儲存格來清除目前的選取範圍。

ClearSelection(Int32, Int32, Boolean)

取消選取目前已選取的所有儲存格 (除了指示的儲存格以外),並選擇性地確定所指示的儲存格已選取。

protected:
 void ClearSelection(int columnIndexException, int rowIndexException, bool selectExceptionElement);
protected void ClearSelection (int columnIndexException, int rowIndexException, bool selectExceptionElement);
member this.ClearSelection : int * int * bool -> unit
Protected Sub ClearSelection (columnIndexException As Integer, rowIndexException As Integer, selectExceptionElement As Boolean)

參數

columnIndexException
Int32

要排除的資料行索引。

rowIndexException
Int32

要排除的資料列索引。

selectExceptionElement
Boolean

true 表示選取被排除的儲存格、資料列或資料行,false 則表示保留其原始狀態。

例外狀況

columnIndexException 大於最高的資料行索引。

-或-

SelectionModeFullRowSelect 時,columnIndexException 小於 -1;否則 columnIndexException 小於 0。

-或-

rowIndexException 大於最高的資料列索引。

-或-

SelectionModeFullColumnSelect 時,rowIndexException 小於 -1;否則 rowIndexException 小於 0。

備註

rowIndexException-1 的值代表資料行標頭,而 columnIndexException -1 的值則代表資料列標頭。

這個方法有助於清除目前的選取範圍,而不取消例外狀況索引所指示之儲存格、資料列或資料行的選取範圍。

SelectionMode如果屬性值允許個別儲存格選取,這個方法會將每個儲存格的 屬性設定 Selectedfalse ,不包括指定之列和資料行中的儲存格。 SelectionMode如果屬性值允許完整資料列或資料行選取,這個方法也會將每個資料列或資料行的 屬性設定 Selectedfalse ,不包括包含指定儲存格的資料列或資料行。

呼叫此方法時,排除的資料格、資料列或資料行可能處於選取狀態。 如果參數值為 trueselectExceptionElement 這個方法會選取它。 視選取模式而定,也可能選取整個資料列或資料行作為結果。

另請參閱

適用於

ClearSelection()

取消選取所有選取的儲存格來清除目前的選取範圍。

public:
 void ClearSelection();
public void ClearSelection ();
member this.ClearSelection : unit -> unit
Public Sub ClearSelection ()

範例

下列程式碼範例會清除 的 DataGridView 選取範圍。 若要執行此範例,請將程式碼貼到包含 DataGridView 具名 dataGridView1Button 具名 clearSelectionButton 的表單中,並確定所有事件都與其事件處理常式相關聯。

private void clearSelectionButton_Click(object sender, EventArgs e)
{
    dataGridView1.ClearSelection();
}
Private Sub clearSelectionButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles clearSelectionButton.Click

    dataGridView1.ClearSelection()

End Sub

備註

呼叫這個方法時,每個資料行和資料列的 Selected 屬性都會設定為 false

另請參閱

適用於