Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to display the full image in datagridview cell

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 belowtotal grid view image

i want to display this image in actual product image column for every cell in that column actual image need to show in every row

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;
    }
like image 932
Glory Raj Avatar asked Aug 18 '11 13:08

Glory Raj


1 Answers

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;
                }
like image 134
platon Avatar answered Oct 10 '22 03:10

platon