DataGridView.CurrentCell 속성

정의

현재 활성화된 셀을 가져오거나 설정합니다.

public:
 property System::Windows::Forms::DataGridViewCell ^ CurrentCell { System::Windows::Forms::DataGridViewCell ^ get(); void set(System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell CurrentCell { get; set; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell? CurrentCell { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.CurrentCell : System.Windows.Forms.DataGridViewCell with get, set
Public Property CurrentCell As DataGridViewCell

속성 값

현재 셀을 나타내는 DataGridViewCell이거나, 현재 셀이 없는 경우 null입니다. 기본값은 첫 번째 열의 첫 번째 셀이거나, 컨트롤에 셀이 없는 경우 null입니다.

특성

예외

현재 셀에 대한 변경 내용을 커밋하거나 취소할 수 없기 때문에 이 속성의 값을 설정할 수 없습니다.

또는

이 속성을 설정할 때 지정된 셀이 숨겨진 행 또는 열 내에 있습니다.

재진입 호출은 DataGridViewDataSource에 바인딩될 때만 허용됩니다. 재진입 호출은 기본 데이터의 변경으로 인해 발생합니다.

이 속성을 설정할 때 지정된 셀이 DataGridView 내에 있지 않습니다.

예제

다음 코드 예제를 통해 검색 CurrentCell 된 셀에 속성을 설정 FirstDisplayedCell 하 여 정렬 후 현재 셀을 표시 하는 방법을 보여 줍니다는 속성입니다. 이 코드는 언바운드 DataGridView 컨트롤에서만 작동합니다. 외부 데이터 원본에 DataGridView 바인딩된 컨트롤을 사용하면 정렬할 때 현재 셀이 자동으로 유지되지 않습니다.

이 예제를 실행하려면 다음 코드를 라는 dataGridView1가 포함된 양식에 붙여넣습니다DataGridView. C#에서는 이벤트 처리기에 Sorted 도 이벤트를 연결해야 합니다.

private void dataGridView1_Sorted(object sender, EventArgs e)
{
    this.dataGridView1.FirstDisplayedCell = this.dataGridView1.CurrentCell;
}
Private Sub dataGridView1_Sorted(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles dataGridView1.Sorted

    Me.dataGridView1.FirstDisplayedCell = Me.dataGridView1.CurrentCell

End Sub

설명

셀을 현재 셀로 설정하면 현재 셀이 표시되지 않으면 보기로 스크롤됩니다. 현재 셀은 머리글 셀, 비활성화된 셀 또는 숨겨진 행 또는 열의 셀일 수 없습니다.

포커스 사각형을 null 일시적으로 제거하도록 이 속성을 로 설정할 수 있지만 컨트롤이 포커스를 받고 이 속성 null의 값이 이면 속성 값 FirstDisplayedCell 으로 자동으로 설정됩니다.

이 속성 SelectionChanged 의 값을 변경하면 이벤트가 이벤트 전에 CurrentCellChanged 발생합니다. 현재 속성에 CurrentCell 액세스하는 모든 SelectionChanged 이벤트 처리기는 이전 값을 가져옵니다.

를 외부 데이터 원본에 바인딩 DataGridView 하면 이 속성이 기본값으로 다시 설정됩니다.

적용 대상

추가 정보