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
close icon

Hosting generic controls and drawing the focus rectangle around it

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

4 Replies

AD Administrator Syncfusion Team November 7, 2006 08:42 AM UTC

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


AD Administrator Syncfusion Team November 7, 2006 05:02 PM UTC

Haneef,

Thanks for the quick answer.

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

Regards,
Andrew


AD Administrator Syncfusion Team November 8, 2006 05:28 AM UTC

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


AD Administrator Syncfusion Team November 8, 2006 04:01 PM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon