You can try to re-paint the DataGridViewCheckBox. And use graphics.DrawString, graphics.DrawImage to draw the file name and file icon.
Here is a simple demo.
public class CustomCheckBoxColumn : DataGridViewCheckBoxColumn
{
private string label;
public string Label
{
get { return label; }
set { label = value; }
}
public override DataGridViewCell CellTemplate
{
get { return new CustomCheckBoxCell(); }
}
}
public class CustomCheckBoxCell : DataGridViewCheckBoxCell
{
// checkbox string
private string label;
public string Label
{
get { return label; }
set { label = value; }
}
// checkbox icon
private Image icon;
public Image Icon
{
get { return icon; }
set { icon = value; }
}
// override Paint
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
// the base Paint
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
// get the check box bounds
Rectangle contentBounds = this.GetContentBounds(rowIndex);
// the string location
Point stringLocation = new Point();
stringLocation.Y = cellBounds.Y + 2;
stringLocation.X = cellBounds.X + contentBounds.Right + 20;
// paint the string.
if (this.Label == null)
{
CustomCheckBoxColumn col = (CustomCheckBoxColumn)this.OwningColumn;
this.label = col.Label;
}
graphics.DrawString(
this.Label, Control.DefaultFont, System.Drawing.Brushes.Black, stringLocation);
// the icon rectangel
Rectangle rectangle = new Rectangle(cellBounds.X + 15, cellBounds.Y + 2, 15, 15);
// paint icon
graphics.DrawImage(icon, rectangle);
}
}
Then create the custom DataGridViewCheckBox in Form_Load.
private void Form1_Load(object sender, EventArgs e)
{
CustomCheckBoxColumn col = new CustomCheckBoxColumn();
col.Width = 130;
col.Label = "this is a test string";
col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
this.dataGridView1.Columns.Add(col);
this.dataGridView1.RowCount = 3;
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
((CustomCheckBoxCell)row.Cells[0]).Label = "this is a test string";
((CustomCheckBoxCell)row.Cells[0]).Icon = Image.FromFile(@"C:\Users\Administrator\Desktop\a.ico");
dataGridView1.Refresh();
}
}
Test result: