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

Image button and focus

Hi -
I am creating an image button using the approach where i set the type to pushbutton and then handle DrawCellButton. The problem is that when the cell has focus, there is no focus rectangle visible. I've tried setting the bordermargin for the cell, but this doesn't work. How can i get the button to show when it is the current cell?
Thanks,
Julie

5 Replies

HA haneefm Syncfusion Team March 28, 2007 09:32 PM UTC

Hi Julie,

If you want to display images in arbitrary pushbutton cell type, it probably will be simpler to handle the DrawCell event, and just draw the image there after the grid has finished doing its default drawing. Please try the attached sample and let me know if this helps.

private void gridControl1_DrawCell(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
if (e.Style.CellType == "PushButton" && e.RowIndex > 0 )
{
//to cancel the default drawing in a grid
e.Cancel = true;

e.Style.Description = string.Empty;
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Rectangle crect = e.Bounds;
crect.Inflate(-5,-5);
e.Graphics.DrawImage(this.imageList1.Images[e.RowIndex % this.imageList1.Images.Count ], crect);
}
}

Best regards,
Haneef


JL Julie Levy March 28, 2007 10:11 PM UTC

Hi -
thanks for you response. If you tab through the grid in the example you provided, the same issue exists. When you get to the image button cell, the focus rectangle is gone.
Sorry, i forgot to mention that i'm in the latest version, Visual Studio 2005.
Thanks,
Julie


HA haneefm Syncfusion Team March 28, 2007 10:36 PM UTC

Hi Julie,

Please try this code snippet.

private void gridControl1_DrawCell(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
if (e.Style.CellType == "PushButton" && e.RowIndex > 0 )
{
//to cancel the default drawing in a grid
e.Cancel = true;

Rectangle crect = e.Bounds;
crect.Inflate(-1, -1);
e.Style.Description = string.Empty;
e.Renderer.Draw(e.Graphics, crect, e.RowIndex, e.ColIndex, e.Style);

crect.Inflate(-2, -2);
e.Graphics.DrawImage(this.imageList1.Images[e.RowIndex % this.imageList1.Images.Count], crect);

crect.Offset(-1, -1);
crect.Inflate(2, 2);
if (e.Renderer.Grid.CurrentCell.RowIndex == e.RowIndex &&
e.Renderer.Grid.CurrentCell.ColIndex == e.ColIndex)
{
e.Graphics.DrawRectangle(Pens.Black, crect);
}
}
}

Best regards,
Haneef


JL Julie Levy March 29, 2007 07:20 PM UTC

Hi -
this is better. However, the focus rectangle remains when the user tabs off of the grid. Is there an event i can trap when the user has tabbed off of the last cell to call refresh?
Thanks,
Julie


JL Julie Levy March 29, 2007 07:21 PM UTC

Also, the image is now a bit distorted. Is there a way to add padding to the cell or column to make it bigger?
Thanks,
Julie

Loader.
Live Chat Icon For mobile
Up arrow icon