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.
Unfortunately, activation email could not send to your email. Please try again.

Image button and focus

Thread ID:

Created:

Updated:

Platform:

Replies:

58808 Mar 28,2007 04:30 PM Mar 29,2007 03:21 PM Windows Forms 5
loading
Tags: GridControl
Julie Levy
Asked On March 28, 2007 04:30 PM

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

haneefm [Syncfusion]
Replied On March 28, 2007 05:32 PM

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

Julie Levy
Replied On March 28, 2007 06:11 PM

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

haneefm [Syncfusion]
Replied On March 28, 2007 06:36 PM

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

Julie Levy
Replied On March 29, 2007 03:20 PM

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

Julie Levy
Replied On March 29, 2007 03:21 PM

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

CONFIRMATION

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.

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.

;