Current filter:
                                You should refresh the page.
                                  • Hi Team,

                                    I'd like to use DirectX painting in my application. Thanks to your documentation, I was able to handle all specific cases in my source code, except one.

                                    I have a CustomDrawColumnHeader event that draws a checkbox in a column header. My source of inspiration was the following ticket.

                                    If you run the attached sample project, you will see the correct behavior (without DirectX). Then go to the source code, switch the _useDirectX flag to True and run the application again. The checkbox is correctly displayed, but the two nodes have disapeared. In fact they are still there: if you click in the treelist at the theoretical position of those two lines, they will show up again.

                                    I found out that removing the "args.Cache.Dispose()" line solves the problem, but I'm not sure whether this solution is correct. I don't want to create memory leaks and this line was certainly there for a good reason in the "no-directX" version. Thanks for your advice!


                                1 Solution

                                Creation Date Importance Sort by

                                Hello Ghislain,

                                Thank you for the sample project. I reviewed it and found that the issue really occurs because the GraphicsCache object is disposed of. And you are right - it should be disposed of when the non-DirectX approach is used because a new GraphicsCache object is created in this line of code:

                                args = new ControlGraphicsInfoArgs(chkinfo, new GraphicsCache(e.Graphics), checkRect);

                                However, when you are using the GraphicsCache object from event arguments for DirectX rendering:

                                args = new ControlGraphicsInfoArgs(chkinfo, e.Cache, checkRect);

                                Disposing of this Cache object brings a painting issue. The correct approach is to use the e.Cache parameter. It's not necessary to dispose of it, you can set the args.Cache parameter to null instead:

                                private void treeList1_CustomDrawColumnHeader(object sender, DevExpress.XtraTreeList.CustomDrawColumnHeaderEventArgs e) { if(e.Column == null) return; Rectangle checkRect = new Rectangle(e.Bounds.Left + 3, e.Bounds.Top + 3, 12, 12); ColumnInfo info = (ColumnInfo)e.ObjectArgs; if(info.CaptionRect.Left < 30) info.CaptionRect = new Rectangle(new Point(info.CaptionRect.Left + 15, info.CaptionRect.Top), info.CaptionRect.Size); e.Painter.DrawObject(info); CheckEditViewInfo chkinfo; CheckEditPainter painter; ControlGraphicsInfoArgs args; chkinfo = riCheck.CreateViewInfo() as CheckEditViewInfo; painter = riCheck.CreatePainter() as CheckEditPainter; chkinfo.EditValue = true; chkinfo.Bounds = checkRect; chkinfo.CalcViewInfo(e.Graphics); args = new ControlGraphicsInfoArgs(chkinfo, e.Cache, checkRect); painter.Draw(args); args.Cache = null; e.Handled = true; }

                                Please test this approach and let me know if it helps.

                                • Ghislain Sommervogel 12.03.2019

                                  Hi Sasha,
                                  Thank you for your detailed answer. Fine for me, I go with your solution!
                                  Have a very nice day,

                                • Sasha (DevExpress Support) 12.03.2019

                                  Hello Ghislain,

                                  I am happy to hear that you found my assistance helpful.

                                  P.S. I reviewed the code of the How to embed a checkbox into a column header and handle clicks on it example and found that the args.Cache.Dispose method is called in the older version of this example. This code is not present in the newer version. I recommend that you always download the latest versions of our examples since there is a chance that the old version contains outdated code or illustrates an outdated approach.

                                • Ghislain Sommervogel 12.03.2019

                                  I take mental note! Thx :-)