[英]giving a dataGridView cell a background image in C#
我想使用.net組件DataGridView從圖像中為行標題和列標題提供自定義背景。 有可能做到這一點嗎? 如果是這樣,怎么樣?
我使用Visual Studio 2008,Windows應用程序,C#。
可以更改datagridview rowheader的屬性。 您需要處理CellPainting或RowPostPaint事件,並在行標題單元格中手動繪制圖像。
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
// Your code to insert image/content per cell goes here
}
在這樣做的方法是在RowDataBound事件中為每個標題元素添加一個cssClass名稱,並在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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.