This is a migrated thread and some comments may be shown as answers.

Paint VisualItem

2 Answers 123 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Froggie
Top achievements
Rank 1
Froggie asked on 04 Apr 2012, 11:37 AM
Hello!

I have a custom VisualItem "CustomVisualItem : IconListViewVisualItem" which belongs to a ListView with ViewType=IconsView.
The VisualItem consits of a StackLayoutPanel with 2 LightVisualElements (one is displaying a image and the other displays text).
The Datasource for the ListView is "List<CustomClass>".

Now I want to achieve the following:
- check if VisualItem is Databound to CustomClass
- when property "Disabled" of CustomClass is true then draw a red X over the VisualItem (a red line from Top-Left to Bottom-Right and one from Top-Right to Bottom-Left)

This is my current not working solution:
internal class CustomVisualItem : IconListViewVisualItem
    {
 
protected override void PaintElement(Telerik.WinControls.Paint.IGraphics graphics, float angle, SizeF scale)
        {
            base.PaintElement(graphics, angle, scale);
 
            var t = this.Data.DataBoundItem as CustomClass;
            if (t != null)
            {
                if CustomClass.Disabled)
                {
                    //To shorten the sample, only draw a rectangle                   
                    graphics.FillRectangle(BoundingRectangle, Color.Silver); // The rectangle is not placed over the VisualItem                
                }
            }       
        }
}

How can I place the red X (or the rectangle) over the VisuaItem?

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 09 Apr 2012, 12:27 PM
Hello Froggie,

Thank you for writing.

The PaintElement method is used for painting the actual element and you cannot draw over child elements. When you add child elements to an element they are placed over their parent. This way your X or rectangle is drawn, but is then covered by the child elements. What you can do is to add another element with the size of the parent, which will cover the other child elements and make it visible when the Disabled property is true. In this element you can use the PaintElement method to draw the X.

I hope this will be useful for you. If you have further questions, I would be glad to help.

Greetings,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Froggie
Top achievements
Rank 1
answered on 13 Apr 2012, 11:41 AM
Thank you!
I still have to make some tweaks, but I think that solved my problem.
If the problem is not solved, then I will let you know it. :-)
Tags
ListView
Asked by
Froggie
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Froggie
Top achievements
Rank 1
Share this question
or