|
// MyViewController.cs
GridTextColumn customerIdColumn = new GridTextColumn();
customerIdColumn.UserCellType = typeof(CustomCell);
customerIdColumn.MappingName = "CustomerID";
dataGrid.Columns.Add(customerIdColumn);
dataGrid.GridStyle = new GridStyle();
// CustomCell.cs
public override void LayoutSubviews()
{
base.LayoutSubviews();
// Set the background color of the column .
this.BackgroundColor = UIColor.Yellow;
this.label.Frame = new CGRect(10, Bounds.Top, Bounds.Width, Bounds.Height);
this.label.Text = DataColumn.CellValue.ToString();
}
public override void Draw(CGRect rect)
{
base.Draw(rect);
var context = UIGraphics.GetCurrentContext();
// Set the border thickness of the column.
context.SetLineWidth(3f);
// Set the border color for the column.
UIColor.Red.SetStroke();
var path = new CGPath();
path.AddLines(new CGPoint[] { new CGPoint(Bounds.Left, Bounds.Top), new CGPoint((Bounds.Left), Bounds.Bottom) });
path.AddLines(new CGPoint[] { new CGPoint(Bounds.Right, Bounds.Top), new CGPoint(Bounds.Right, Bounds.Bottom) });
path.AddLines(new CGPoint[] { new CGPoint(Bounds.Left, Bounds.Bottom), new CGPoint((Bounds.Right), Bounds.Bottom) });
path.CloseSubpath();
context.AddPath(path);
context.DrawPath(CGPathDrawingMode.FillStroke);
path = null;
context = null;
}
// GridStyle.cs
public class GridStyle : DataGridStyle
{
public override GridLinesVisibility GetGridLinesVisibility()
{
return GridLinesVisibility.Both;
}
}
|