我在DatagridView
中顯示了一些行,它們將第一列設置爲ImageandText.when用戶選擇任何一行,直到具有文本部分的單元格保持圖像背景爲白色。用於DataGridView中的第一單元顯示所述圖像和文本在ImageandText中只選擇文本Datagridview列
代碼:
private void dgvLogDetails_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == 0)
{
e.PaintBackground(e.ClipBounds, true);
PointF p = e.CellBounds.Location;
e.CellStyle.SelectionBackColor = Color.White;
p.X += imgList.ImageSize.Width+8;
e.Graphics.DrawImage(imgList.Images[1], e.CellBounds.X+4,
e.CellBounds.Y, 16, 16);
e.Graphics.DrawString(e.Value.ToString(),
e.CellStyle.Font, Brushes.Black, p);
e.Handled = true;
}
}
上述代碼選擇,如下面圖中所示的完整細胞(圖像和文本):
我想有像在下面的圖片[預計]:
嘗試斯利拉姆代碼,它是如下顯示:
我不知道,但我想'ListView'默認情況下將有你問的功能。如果可行,你可以使用'ListView'。 – 2014-09-19 11:32:41
實際上我所顯示的預期圖像是使用'ListView'創建的。現在我正在改變它'DataGridView' – 2014-09-19 11:45:41
哦,忽視我的評論然後,看看我的答案是否有幫助。 – 2014-09-19 11:58:15