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.

Hosting generic controls and drawing the focus rectangle around it

Thread ID:

Created:

Updated:

Platform:

Replies:

51473 Nov 6,2006 09:14 PM Nov 8,2006 11:01 AM Windows Forms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On November 6, 2006 09:14 PM

Hi,

It looks like the "focus" rectangle is drawn inside the cell; if you host a custom control, it occupies the whole cell so there is no way to see which control has focus. Of course, you can draw the black border in custom control, but we have many of them, and some of them don't support such behavior. Is is possible to simply draw the black gridlines around the active cell instead of drawing them inside the cell?

Thanks a lot
-Andrew

Administrator [Syncfusion]
Replied On November 7, 2006 03:42 AM

Hi Andrew,

If you want to draw the focus rectangle in arbitrary cell types, it probably will be simpler to handle the CellDrawn event, and just draw the focusrectanlge there after the grid has finished doing its default drawing. Below is a code snippet

GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
if( cc != null
&& cc.RowIndex == e.RowIndex
&& cc.ColIndex == e.ColIndex
&& e.Style.CellType == "MyCellType" )
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
e.Cancel = true;

//Draw the focus rctangle Here...
Rectangle rect = e.Bounds;
rect.Inflate(- 5,-5);
rect.Size = new Size(rect.Width -5 ,rect.Height - 5);
e.Graphics.DrawRectangle( Pens.Black,rect);
}

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 7, 2006 12:02 PM

Haneef,

Thanks for the quick answer.

Your example works perfectly for all cell renderers except those that host custom controls :)

Regards,
Andrew

Administrator [Syncfusion]
Replied On November 8, 2006 12:28 AM

Hi Andrew,

You need to override the OnDraw method of your custom cell renderer. Here is a code snippet for drawing focused rectangle in Calender cell.

protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
{
clientRectangle.Size = GridUtil.Max(clientRectangle.Size, CalendarCellModel.CalendarControlSize);
if (this.ShouldDrawFocused(rowIndex, colIndex))
{
style.Control = editCalendar;
g.DrawRectangle( new Pen(Brushes.Black,5f),clientRectangle);
clientRectangle.Size = new Size(clientRectangle.Width - 5,clientRectangle.Height - 5);
}
else
{
style.Control = drawCalendar;
CalendarCellModel.InitializeCalendar(drawCalendar, style);
}
base.OnDraw (g, clientRectangle, rowIndex, colIndex, style);
}

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/CalendarCells_2003_b182a1b1.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 8, 2006 11:01 AM

Haneef,

Thanks a lot for the example! I didn't know that it's possible to modify clientRectangle... simply inserting

clientRectangle.Inflate(-2, -2);

before base.OnDraw() did the trick for me.

Thanks again!
Andrew

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.

;