Windows Develop Bookmark and Share   
 index > Windows Forms Designer > how to display images in DataGridView?
 

how to display images in DataGridView?

i want to display the images in one dirctoryin which the files areall imagesin the DataGridView?Could somebody give me some instructions or tips?Thank you so much!!!

wilbyang  Wednesday, August 19, 2009 3:53 PM
//Create one DataGridViewImageColumn and add to DataGridView1

    DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();    
    imageColumn.Name = "Image";    
    imageColumn.HeaderText = "Show Image";    
    DataGridView1.Columns.Add(imageColumn);
    

//get image files
   DirectoryInfo di = new DirectoryInfo(/*directory path*/);
FileInfo[] images = di.GetFiles("*.jpg");
    
    
    // Assign thumbnails images to each cell of DataGridViewImageColumn    
    DataGridView1.RowCount =images.Length;
    
    for (int i = 0; i <= DataGridView1.RowCount - 1; i++) 
{
        
            
        DataGridView1.Rows[i].Cells[0].Value = Image.FromFile(images[i].FullName);
    }



  • Marked As Answer bywilbyang Thursday, August 20, 2009 4:19 PM
  •  
NareshG  Wednesday, August 19, 2009 7:57 PM
//Create one DataGridViewImageColumn and add to DataGridView1

    DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();    
    imageColumn.Name = "Image";    
    imageColumn.HeaderText = "Show Image";    
    DataGridView1.Columns.Add(imageColumn);
    

//get image files
   DirectoryInfo di = new DirectoryInfo(/*directory path*/);
FileInfo[] images = di.GetFiles("*.jpg");
    
    
    // Assign thumbnails images to each cell of DataGridViewImageColumn    
    DataGridView1.RowCount =images.Length;
    
    for (int i = 0; i <= DataGridView1.RowCount - 1; i++) 
{
        
            
        DataGridView1.Rows[i].Cells[0].Value = Image.FromFile(images[i].FullName);
    }



  • Marked As Answer bywilbyang Thursday, August 20, 2009 4:19 PM
  •  
NareshG  Wednesday, August 19, 2009 7:57 PM
thank you so much!!!
wilbyang  Thursday, August 20, 2009 4:24 PM
which method or eventhandler of the DataGridView should i put the above codes in?
wilbyang  Thursday, August 20, 2009 4:36 PM
Its depends when you need to display images in datagridview. If you need to display as form show, then you can use Form_Load event.
NareshG  Thursday, August 20, 2009 5:13 PM
thank you so much for your help.the images did display in the DataGridView.as i ama novice to dot net windows app development,i've no ideahow to set the size(the width and the heighth) for each image to display.could you give me somemore advice?
wilbyang  Friday, August 21, 2009 12:39 AM

You can use google to search for other answers

Custom Search

More Threads

• Why doesn't the myCollection property show in run time?
• Moving from Java to C#
• Read outlook email and then save data into SQL server
• databound Datagridview textbox column to Datagridview combobox column during runtime
• Collection property in User Control
• ActiveX Control in Windows Service designer
• Serialization of custom colors (and other types)
• ToolboxBitmap doesn't work
• User Control + URI formats are not supported
• Intellisense won't work on many collections