DataGridView.CellMouseClick 이벤트

정의

사용자가 마우스로 셀의 임의 지점을 클릭할 때마다 발생합니다.

public:
 event System::Windows::Forms::DataGridViewCellMouseEventHandler ^ CellMouseClick;
public event System.Windows.Forms.DataGridViewCellMouseEventHandler CellMouseClick;
public event System.Windows.Forms.DataGridViewCellMouseEventHandler? CellMouseClick;
member this.CellMouseClick : System.Windows.Forms.DataGridViewCellMouseEventHandler 
Public Custom Event CellMouseClick As DataGridViewCellMouseEventHandler 

이벤트 유형

예제

다음 코드 예제에서는이 멤버를 사용 하는 방법을 보여 줍니다. 예제에서는 이벤트 처리기에서 보고서를 CellMouseClick 이벤트입니다. 이 보고서를 통해 이벤트 발생 하 고 도움이 될 수 있습니다 디버깅 하는 경우를 학습할 수 있습니다. 자주 발생 하는 이벤트 또는 여러 이벤트를 보고 하려면 바꾸는 것이 좋습니다 MessageBox.Show 사용 하 여 Console.WriteLine 줄에 메시지를 추가 또는 TextBox합니다.

예제 코드를 실행 하려면 형식의 인스턴스를 포함 하는 프로젝트에 붙여넣습니다 DataGridView 라는 DataGridView1합니다. 연결 된 이벤트 처리기는 확인 된 CellMouseClick 이벤트입니다.

private void DataGridView1_CellMouseClick(Object sender, DataGridViewCellMouseEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Button", e.Button );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Clicks", e.Clicks );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "X", e.X );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Y", e.Y );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Delta", e.Delta );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Location", e.Location );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "CellMouseClick Event" );
}
Private Sub DataGridView1_CellMouseClick(sender as Object, e as DataGridViewCellMouseEventArgs) _ 
     Handles DataGridView1.CellMouseClick

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Button", e.Button)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Clicks", e.Clicks)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "X", e.X)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Y", e.Y)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Delta", e.Delta)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Location", e.Location)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"CellMouseClick Event")

End Sub

설명

이 이벤트는 사용자가 마우스 단추를 사용하여 클릭할 때 발생합니다. 사용 된 MouseEventArgs.Button 단추를 확인 하려면 속성입니다.

셀 내의 단추 또는 링크와 같은 셀 내용에 대한 클릭을 감지하려면 이벤트를 사용합니다 CellContentClick .

이 이벤트의 처리기는 마우스 포인터 위치의 열 인덱스 및 행 인덱스를 받습니다.

에서 클릭하는 DataGridViewCheckBoxCell경우 이 이벤트는 검사 상자가 값을 변경하기 전에 발생하므로 현재 값을 기준으로 예상 값을 계산하지 않으려면 일반적으로 이벤트를 대신 처리 CellValueChanged 합니다. 이 이벤트는 일반적으로 포커스가 셀을 떠날 때 발생하는 사용자 지정 값이 커밋될 때만 발생하므로 이벤트도 처리 CurrentCellDirtyStateChanged 해야 합니다. 해당 처리기에서 현재 셀이 검사 상자 셀인 경우 메서드를 CommitEdit 호출하고 값을 전달합니다Commit.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보