PushButton with Image in GridGroupingControl

I want to create a column with PushButtons and Image drawn ON TOP of a themed push button.

In OnQueryCellStyleInfo I have:
e.Style.CellType = "PushButton";
e.Style.Themed = true;
e.Style.ImageList = imageList;
e.Style.ImageIndex = 0;
e.Style.ImageSizeMode = GridImageSizeMode.CenterImage;

This gives me push button but without the image (I have image list set up).

If I use e.Style.CellType = "Image" I get an image from image list drawn and centered, but I want to have pushbutton style theme around it.
Is there a way to do this?

I found similar posts here but they were not very helpful:
https://www.syncfusion.com/forums/16806/use-button-image-in-gridgroupingcontrol
https://www.syncfusion.com/forums/77780/how-to-add-an-image-on-an-pushbutton-in-a-gridgrouping-control

1 Reply

AR Arulpriya Ramalingam Syncfusion Team December 26, 2017 08:46 AM UTC

Hi Petar,   
   
Thanks for contacting Syncfusion support.   
   
By default, the button will be drawn in the cell when the CellType is set as “PushButton” and the image will be drawn in the cell when the CellType is set as “Image”. The GridGroupingControl does not have the direct support to draw the image in a push button cell. This can be achieved by using the DrawCellButton event of TableControl. In that event Draw() method of GridCellButton can be used to draw the button and DrawImage() method can be used to draw image on PushButton. Please refer to the below code example and sample,   
   
Code example   
   
//Event Triggering      
this.gridGroupingControl1.TableControl.DrawCellButton += TableControl_DrawCellButton;      
   
//Event Customization    
private void TableControl_DrawCellButton(object sender, GridDrawCellButtonEventArgse)    
   
    if (e.Style.CellType == GridCellTypeName.PushButton)    
    {    
        Rectangle rect = e.Button.Bounds;    
        rect.X += e.Button.Bounds.Width / 3;    
        rect.Width = e.Button.Bounds.Width / 3;    
    
        Bitmap bitmap = new Bitmap(SystemIcons.Error.ToBitmap());    
        //To draw image in Buttoncell    
        e.Button.Draw(e.Graphics, e.RowIndex, e.ColIndex, true, e.Style);    
        e.Graphics.DrawImage(bitmap, rect);    
        e.Cancel = true   
    }    
   
   
Screenshot   
     
   
   
Regards,   
Arulpriya 



Loader.
Up arrow icon