我需要创建一个允许以下内容的新DataGridView列类型:
一步一步,我试图让它至少正确地显示图像。这是我的代码:
public class DataGridViewPODColumn : DataGridViewColumn
{
public DataGridViewPODColumn()
{
this.CellTemplate = new DataGridViewPODCell();
}
public override object Clone()
{
return base.Clone()
}
}
这是细胞的代码:
public class DataGridViewPODCell : DataGridViewTextBoxCell
{
private static Type defaultValueType = typeof(List<PODImage>);
private int _XCoordinate = 0;
private int _YCoordinate = 0;
public int XCoordinate { get { return _XCoordinate; } set { _XCoordinate = value; } }
public int YCoordinate { get { return _YCoordinate; } set { _YCoordinate = value; } }
public override Type ValueType
{
get
{
Type valueType = base.ValueType;
if (valueType != null) return valueType;
return defaultValueType;
}
}
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (this.DataGridView == null) return;
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
int counter = 0;
foreach (PODImage podVal in (List<PODImage>)value)
{
GraphicsContainer container = graphics.BeginContainer();
graphics.SetClip(cellBounds);
Point objPoint = new Point(cellBounds.Location.X + XCoordinate, cellBounds.Location.Y + YCoordinate);
graphics.DrawImage(podVal.POD, objPoint.X, objPoint.Y, 20, 40);
XCoordinate += 22;
counter++;
if (counter % 3 == 0)
{
YCoordinate += 42;
XCoordinate = 0;
}
}
}
但是,我有一些重大问题:
我知道这可能是相当基本的东西!我是Windows Forms开发的新手,过去一年只在ASP.NET中工作过......哦,我是如何渴望我的GridView和TemplateField的呢!
如果有人能指出我正确的方向,我会非常感激。