//Set the Horizontal Alignment of the column in constructor or form load.
this.sfDataGrid1.Columns["Open"].CellStyle.HorizontalAlignment = HorizontalAlignment.Center;
this.sfDataGrid1.Columns["Map"].CellStyle.HorizontalAlignment = HorizontalAlignment.Center;
void sfDataGrid1_QueryButtonCellStyle(object sender, QueryButtonCellStyleEventArgs e)
{
//Finds the column with
if (e.Column.MappingName.Equals("Open"))
{
//if the project exists then have an open icon else have a different icon
if (Directory.Exists(projectFolderPath))
{
e.Button.Image = Properties.Resources.open.ToBitmap();
e.Button.ImageSize = new System.Drawing.Size(w, h);
}
else
{
e.Button.Image = Properties.Resources.failedopen.ToBitmap();
e.Button.ImageSize = new System.Drawing.Size(w, h);
}
}
//Another button with another icon
if (e.Column.MappingName.Equals("Map"))
{
var w = Properties.Resources.edit.Width / 4;
var h = Properties.Resources.edit.Height / 4;
e.Button.Image = Properties.Resources.map.ToBitmap();
e.Button.ImageSize = new System.Drawing.Size(w, h);
}
}
|