为什么在DataGridView中的SelectionChanged事件时不会触发CellClick事件?

时间:2013-09-05 14:29:03

标签: c# datagridview

当我选择一行但dataGridView1_CellClick事件未触发时,

dataGridView1_SelectionChanged事件触发。我只使用一个网格。

private void mgInvoice_SelectionChanged(object sender, EventArgs e)
        {
            if (this.IsFlagForShowImage)
            {
                ////If show image flag is true then only show images for invoices.
                try
                {
                    if (this.mgInvoice.SelectedRows != null)
                    {
                        if (this.mgInvoice.SelectedRows.Count > 0)
                        {
                            invoice = this.mgInvoice.SelectedRows[0].DataBoundItem as TAPInvoice;

                        Thread th = new Thread(new ThreadStart(LoadDocumentIdByInvoice));
                        th.Start();

                        this.ShowInvoiceImageDocumentByDocId(this.invoice);
                        IsModifiedCollection = true;

                        //Zahid
                        this.SetPriviliges();
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {

            }
        }
    }

上述事件正确触发。但是下面提到的事件不会发生。

private void mgInvoice_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.mgInvoice.Columns["FImagesReviewed"].Visible)
            {
                this.mgInvoice.Columns["FImagesReviewed"].Visible = true;

            }
        else if (this.mgInvoice.Columns["FImagesApproved"].Visible)
        {
            this.mgInvoice.Columns["FImagesApproved"].Visible = true;
        }
    }

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。在SelectionChanged事件处理程序中对DataGridView的CurrentCell进行了赋值:

_DataGridView.CurrentCell = cellToSelect;

删除此分配后,CellClick事件再次被触发。

相关问题