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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridControl: Left & Right images in cells

Thread ID:





16748 Jul 23,2004 06:18 AM UTC Jul 23,2004 07:05 AM UTC WinForms 1
Tags: GridControl
Mario Cadelli
Asked On July 23, 2004 06:18 AM UTC

Hi, Like in a TreeNodeAdv object, I would like to have a grid cell displaying normal text and various images (example:2 at the left and 1 at the right - showing various status). The only thing I have seen is that I can put a text and a left image like this: mygrid[1,1].CellValue = "My Text"; mygrid[1,1].ImageList = myImageList; mygrid[1,1].ImageIndex = 0; Is it possible with the GridControl to have cells with more images (left & right)? Thanks Mario

Administrator [Syncfusion]
Replied On July 23, 2004 07:05 AM UTC

There are several sandard ways to include pictures in a cell including the one you mentioned. But they all work with a single picture. But it is straight forward task to include as many pictures as you like in a cell, and to position them anyway you want them. You can do this either using a grid.CellDrawn event or deriving a custom celltype that is ''many-picture-aware''. Here is code that puts 3 pictures, one to the left and two to the right using the grid CellDrawn event. This code expects you to reserve the space for the picture by setting the style.TextMargins and to specify the 3 pictures by setting them in order in the style.ImageList property. (The same kind of thing can be used in a custom cell control.) //in formload... //get the images somehow.... ImageList images = new ImageList(); images.Images.Add(SystemIcons.Asterisk.ToBitmap()); images.Images.Add(SystemIcons.Hand.ToBitmap()); images.Images.Add(SystemIcons.Question.ToBitmap()); GridStyleInfo style = this.gridControl1[2,2]; style.Text = "Some Text"; style.ImageList = images; //3 images int pictureWidth = images.ImageSize.Width + 2; style.TextMargins.Left = pictureWidth; //1 on left style.TextMargins.Right = 2 * pictureWidth; //2 on right this.gridControl1.ColWidths[2] = 3 * pictureWidth + 65; //65 is the text width part this.gridControl1.CellDrawn += new GridDrawCellEventHandler(grid_DrawCell);
private void grid_DrawCell(object sender, GridDrawCellEventArgs e)
	if(e.ColIndex == 2 && e.RowIndex == 2)
		Rectangle rect = e.Bounds;
		int w = e.Style.ImageList.ImageSize.Width + 2;
		//draw image0
		rect.Width = w;
		GridStaticCellRenderer.DrawImage(e.Graphics, e.Style.ImageList, 0, rect);
		//draw image1
		rect.X = rect.X + e.Bounds.Width - 2 * w;
		GridStaticCellRenderer.DrawImage(e.Graphics, e.Style.ImageList, 1, rect);
		//draw image2
		rect.X = rect.X + w;
		GridStaticCellRenderer.DrawImage(e.Graphics, e.Style.ImageList, 2, rect);


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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