2010-09-02 76 views

回答

1

您可以處理CellPainting事件,檢查標誌的狀態,然後繪製要顯示/隱藏的單元格。

MSDN上這個鏈接可以幫助你在此:

http://msdn.microsoft.com/en-us/library/hta8z9sz.aspx

+0

感謝。此刻,我正在使用DataBindingComplete事件並將隱藏單元格設置爲只讀,並將所有顏色更改爲SystemColors.Window。覆蓋Paint事件也會讓我殺死單元格邊界,但由於我有幾種不同的單元格類型,因此我不能僅將示例代碼作爲完整的解決方案。目前我認爲如果我在邊界上揮之不去,我只會注意到這是一個選項。 – 2010-09-03 17:48:57

0

這裏是我的榜樣。爲CellPainting添加一個事件處理程序,然後確定該項目是否被禁用。如果它被禁用,則只需繪製背景並使單元格爲只讀。

我有一個自定義類BoardStatusView綁定到數據網格,它有一個布爾函數,確定如果小區應該有一個複選框或不(Upgradeable()

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
    { 
     if (e.RowIndex >= 0) 
     { 
      BoardStatusView bs = dataGridView1.Rows[e.RowIndex].DataBoundItem as BoardStatusView; 
      bool disabled = !bs.Upgradeable(); 
      dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = disabled; 
      if (disabled && e.ColumnIndex == 0) 
      { 
       e.PaintBackground(e.ClipBounds, false); 
       e.Handled = true; 
      } 
     } 
    } 
相關問題