2009-11-12 37 views

回答

2

它可能改變datagridview rowheader的屬性。您需要處理CellPainting或RowPostPaint事件,並在行標題單元格中手動繪製圖像。

protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) 
     { 
      // Your code to insert image/content per cell goes here  
     } 
+0

我仍然無法弄清楚這些代碼如何能幫助我實現這一目標。 我確實試圖重寫RowPostPaint事件,但我仍然不知道如何使用它來爲單元格的背景插入圖像 – Pieter888 2009-11-12 13:21:17

+0

沒關係我想通了,謝謝QuBaR! – Pieter888 2009-11-12 14:53:57

+0

未來的谷歌瀏覽器:同樣的技巧可以用於單元格爲您的單元格提供漸變背景(使用'LinearGradientBrush'),僅使用OnRowPrePaint,並將單元格的默認背景顏色設置爲* Transparent * – 2010-04-08 16:17:57

-2

在這樣做,這是把每個標題元素的名稱的CssClass在RowDataBound事件是這樣,並在指定的CSS背景圖片。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.Header) 
     { 
      foreach (TableCell c in e.Row.Cells) 
      { 
       c.CssClass = "bgimage"; 
      } 
     } 
    } 

CSS:

.bgimage{ background-image:url(images/arrow-red-large-down.gif); 
+0

以及我如何能夠定義css本身。它應該是一個外部文件? – Pieter888 2009-11-13 09:11:06

+0

正確的方法是包含對外部樣式表的引用,但可以在頁面上內聯樣式。 – 2010-01-08 17:49:57

+0

這是ASP.net,而不是winforms – 2010-04-08 16:04:03

相關問題