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

GridControl: Left & Right images in cells

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

1 Reply

AD Administrator Syncfusion Team July 23, 2004 03:05 AM

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);
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon