We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display multiple images in a cell in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 19, 2019
Tags: styling, image

Display multiple images in a grid cell

To display multiple Images in a cell, you need to handle the CellDrawn Event. In the following code example, the image is attained from the ImageList that has the collection of images. In the CellDrawn event handler, the images are drawn in the cell by using the bounds of the rectangle.

C#

//Sets the cellType as Image
this.gridControl1[3, 3].CellType = GridCellTypeName.Image;
Bitmap bmp1 = SystemIcons.Exclamation.ToBitmap();
Bitmap bmp2 = SystemIcons.Question.ToBitmap();
Bitmap bmp3 = SystemIcons.Shield.ToBitmap();
//Adds the bitmaps to the image list
images.Images.Add(bmp1);
images.Images.Add(bmp2);
images.Images.Add(bmp3);
//Hooks the CellDrawn event in Form_Load to add images
this.gridControl1.CellDrawn += gridControl1_CellDrawn;  
void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
{
    if (e.RowIndex ==3 && e.ColIndex==3  )
    {
         Rectangle rect = new Rectangle(e.Bounds.Location, images.ImageSize);
         rect.Intersect(e.Bounds);
         for (int i = 0; i < this.images.Images.Count; ++i)
         {
              GridStaticCellRenderer.DrawImage(e.Graphics, this.images, i, rect, false);
              rect.Offset(this.images.ImageSize.Width + 1, 0);
         }
    }
}

 

VB

'Sets the cellType as Image
Private Me.gridControl1(3, 3).CellType = GridCellTypeName.Image
Private bmp1 As Bitmap = SystemIcons.Exclamation.ToBitmap()
Private bmp2 As Bitmap = SystemIcons.Question.ToBitmap()
Private bmp3 As Bitmap = SystemIcons.Shield.ToBitmap()
'Adds the bitmaps to the image list
images.Images.Add(bmp1)
images.Images.Add(bmp2)
images.Images.Add(bmp3)
'Hooks the CellDrawn event in Form_Load to add images
Me.gridControl1.CellDrawn += gridControl1_CellDrawn
Private Sub gridControl1_CellDrawn(ByVal sender As Object, ByVal e As GridDrawCellEventArgs)     
     If e.RowIndex =3 AndAlso e.ColIndex=3 Then
          Dim rect As New Rectangle(e.Bounds.Location, images.ImageSize)
          rect.Intersect(e.Bounds)
          For i As Integer = 0 To Me.images.Images.Count - 1
               GridStaticCellRenderer.DrawImage(e.Graphics, Me.images, i, rect, False)
               rect.Offset(Me.images.ImageSize.Width + 1, 0)
          Next i
     End If
End Sub

 

GridControl with multiple images in a cell

Figure 1: GridControl with multiple images in a cell.

 

Samples:

C#: MultipleImages

VB: MultipleImages

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon