Aracılığıyla paylaş


DataGridView.CellMouseClick Olay

Tanım

Kullanıcı fareyle bir hücrenin herhangi bir yerine tıklasa gerçekleşir.

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 

Olay Türü

Örnekler

Aşağıdaki kod örneğinde bu üyenin kullanımı gösterilmektedir. Örnekte, olay işleyicisi olayın oluşumunu CellMouseClick bildirir. Bu rapor, olayın ne zaman gerçekleştiğini öğrenmenize yardımcı olur ve hata ayıklamada size yardımcı olabilir. Birden çok olayı veya sık gerçekleşen olayları raporlamak için, iletisini ile MessageBox.Show değiştirmeyi Console.WriteLine veya çok satırlı TextBoxbir iletiye eklemeyi göz önünde bulundurun.

Örnek kodu çalıştırmak için, adlı DataGridViewtürünün DataGridView1 bir örneğini içeren bir projeye yapıştırın. Ardından olay işleyicisinin olayla ilişkilendirildiğinden CellMouseClick emin olun.

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

Açıklamalar

Bu olay, kullanıcı fare düğmelerinden herhangi birini kullanarak tıkladığında oluşur. MouseEventArgs.Button Hangi düğmeye tıklandığını belirlemek için özelliğini kullanın.

Hücrenin içindeki düğme veya bağlantı gibi tıklamaları algılamak için olayı kullanın CellContentClick .

Bu olayın işleyicisi, fare işaretçisi konumunun sütun dizinini ve satır dizinini alır.

içindeki DataGridViewCheckBoxCelltıklamalar için, onay kutusu değeri değiştirmeden önce bu olay gerçekleşir, bu nedenle beklenen değeri geçerli değere göre hesaplamak istemiyorsanız, genellikle olayı işlersiniz CellValueChanged . Bu olay yalnızca kullanıcı tarafından belirtilen değer işlendiğinde gerçekleştiğinden ve genellikle odak hücreden ayrıldığında gerçekleştiğinden, olayı da işlemeniz CurrentCellDirtyStateChanged gerekir. Bu işleyicide, geçerli hücre bir onay kutusu hücresiyse yöntemini çağırın CommitEdit ve değeri geçirin Commit .

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Şunlara uygulanır

Ayrıca bkz.