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

Syncfusion GridGenericControlCellRenderer OnDraw Method error

I have created my own customrenderer extending the GridGenericControlCellrenderer. the custom renderer was written for a specific usercontrol. I wanted to show this usercontrol when the cell has focus and a normal labeltext with the value in it when the cell does not have focus. this is the code i had used to acheive this in the ondraw method protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style) { clientRectangle.Size = GridUtil.Max (new Size(clientRectangle.Width , clientRectangle.Height) , new Size(clientRectangle.Width,DOUBLEUNIT_HEIGHT)); if ( this.ShouldDrawFocused(rowIndex , colIndex) == true ) { style.Control = this.newTextBox; DoubleUnitTextBoxCellModel.InitializeUnitTextBox(this.newTextBox , style); } else { style.Control = this.label; DoubleUnitTextBoxCellModel.InitializeLabel(this.label , style); } base.OnDraw (g, clientRectangle, rowIndex, colIndex, style); } newTextBox happens to be my usercontrol. I get a hdc error message on the base.ondraw method call. I had replaced the label with another of my usercontrols and the code works fine. but when i replaced both my usercontrols with 2 labels the code crashes again with the same error. i observed that when i comment style.control = label the code works fine again. Please help Regards Harsha

4 Replies

AD Administrator Syncfusion Team November 10, 2004 01:24 PM UTC

Have you looked at the grid\samples\celltypes\calendarcells sample? It does something very close to this, except it uses two of the same controls (MonthCalendars) and not two different controls. In particular, does your code have use the same calls in the renderer''s constructor like this sample does? (SetFixedControl and SetControl)?


AD Administrator Syncfusion Team November 11, 2004 07:15 AM UTC

Yes i have looked at the MonthCalendar example. I do use the SetFixedControl and the SetControl methods. the code is as follows this.FixControlParent(label); this.SetControl(newTextBox); so the editable control is my customcontrol and the drawcontrol would be the label. Harsha >Have you looked at the grid\samples\celltypes\calendarcells sample? It does something very close to this, except it uses two of the same controls (MonthCalendars) and not two different controls. > >In particular, does your code have use the same calls in the renderer''s constructor like this sample does? (SetFixedControl and SetControl)?


AD Administrator Syncfusion Team November 11, 2004 08:18 AM UTC

If it works when you do not use the label in the Draw method, you could not use the label and instead use the static method GridStaticCellRenderer.DrawText to draw teh text in the cell and not call the base class in this case. If this does serve your purposes, then if you post a sample project showing this problem with your derived control, maybe I can suggest something else.


AD Administrator Syncfusion Team November 11, 2004 12:04 PM UTC

Thank you that works

Loader.
Live Chat Icon For mobile
Up arrow icon