I have data grid view with columns product name and product image and I am populating these values coming from database...
i am using winforms desktop application.....
my problem is I am not able to showing the image in datagridview cell properly ..see the diagram below
i want to display this image in actual product image column for every cell in that column
this task is very simple in webforms by using datalist control but i dont know how to display full image in grid view cell
can any one help on this....
many thanks.......
and this is where i am binding the datagridview by using linq query..
private void EquipmentFinder_Load(object sender, EventArgs e)
{
var products = from prods in abc.products
select new
{
productid = prods.product_Id, //0
productname = prods.product_Name, //1
productimage = prods.product_Image, //2
productprice = prods.product_Price,//3
productdescr = prods.product_Description, //4
};
productbindingsource.DataSource = products;
productgridview.DataSource = productbindingsource;
productgridview.Columns[0].Visible = false;
productgridview.Columns[3].Visible = false;
productgridview.Columns[4].Visible = false;
}
Set the column's ImageLayout to the Stretch value to resolve this problem.
UPDATE: use the following code to change the ImageLayout property:
for(int i = 0; i < dataGridView1.Columns.Count; i ++)
if(dataGridView1.Columns[i] is DataGridViewImageColumn) {
((DataGridViewImageColumn)dataGridView1.Columns[i]).ImageLayout = DataGridViewImageCellLayout.Stretch;
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With