Reputation: 195
I am stuck up with this thing. Hope you guys help me out in this. This is my c# code
private void button_GetData_Click(object sender, EventArgs e)
{
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
DataGridViewImageColumn img = new DataGridViewImageColumn();
img.ImageLayout = DataGridViewImageCellLayout.Stretch;
object O = Resources.ResourceManager.GetObject("delete_header");
Image image = (Image)O;
img.Image = image;
dataGridView1.Columns.Add(img);
img.HeaderText = "Image";
img.Name = "img";
}
My Image column looks like this
Actual Image:
Its a simple windows form application. Thanks in advance :)
Upvotes: 0
Views: 2496
Reputation: 2171
If you set to "Stretch" your image will be inproportionally scaled to fit whole cell. And that is probably not what you want.
Set to zoom to have The graphic is uniformly enlarged until it fills the width or height of the containing cell.
Upvotes: 1
Reputation: 3388
Set ImageLayout
property of DataGridViewImageColumn
to DataGridViewImageCellLayout.Zoom
.
With this property value, the graphic is uniformly enlarged until it fills the width or height of the containing cell.
Upvotes: 2