Unable to display the full image in datagridview cell

16,883

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;
                }
Share:
16,883
Glory Raj
Author by

Glory Raj

working as a software developer.... At present doing web applications and learning Asp.net MVC..

Updated on June 09, 2022

Comments

  • Glory Raj
    Glory Raj about 2 years

    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;
        }
    
  • Glory Raj
    Glory Raj almost 13 years
    I am not defining columns from designer i am just binding details from database using linq query
  • Glory Raj
    Glory Raj almost 13 years
    how to find the gridviewimagecolumn .. i dint touch the designer.cs see my updated code..
  • platon
    platon almost 13 years
    paste my code below this one: productgridview.Columns[4].Visible = false; The DataGridViewImageColumn is a type declared in the System.Windows.Forms namespace. Please also refer to the msdn.microsoft.com/en-us/library/…
  • Glory Raj
    Glory Raj almost 13 years
    thanq its working now ... is it possible to increase the width and height of the cell like medium sized square box....would you pls give suggestions ...
  • Glory Raj
    Glory Raj almost 13 years
    it does not working i have done like this productgridview.RowTemplate.Height = 200;
  • Glory Raj
    Glory Raj almost 13 years
    its not working .....would you pls suggest any other way to increase the width and height of each cell