簡體   English   中英

DataGridView CellFormatting事件未觸發

[英]DataGridView CellFormatting Event Not Firing

我在DataGridView上為CellFormatting事件添加了一個處理程序,以根據行的內容修改背景顏色。

即使數據插入表中,它似乎也沒有被觸發。 我在CellFormatting事件中通過雙擊來添加事件處理程序,這似乎正確地創建了代碼。

   private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        // this never gets called
        MessageBox.Show("Event fired");
    }

我能做錯什么?

您可以嘗試RowValidated事件:

 private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
 {
        dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Blue;
 }

注意:單擊行和關閉表單時將觸發此事件。

我認為你不能在你的情況下使用CellFormating事件。 當需要格式化單元格的內容以進行顯示時,會發生這種情況。

請嘗試使用CellValueChanged事件(http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx)

要么

http://msdn.microsoft.com/en-us/library/x4dwfh7x.aspx中選擇其他適當的事件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM