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

Accessing child elements of a Custom ListView Item

2 Answers 292 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 11 Mar 2013, 06:31 AM
Hi Guys

I'm want to create a listview of items where the item has a waiting bar which appears when the item is pressed and disappears again once a long running process kicked off by the press has completed. I have successfully built the custom item but when I go to the ItemMouseClick event of the listview I'm not sure how to access the waiting bar element so that I can make it visible and set it running.

Many thanks in advance

regards
Ian Carson

public class RadCustomVariationViewVisualItem : IconListViewVisualItem
   {
       private LightVisualElement _imageElement;
       private LightVisualElement _nameElement;
       private LightVisualElement _descriptionElement;
       private RadWaitingBarElement _waitingBarElement;
       private StackLayoutPanel _overallLayout;
       private StackLayoutPanel _textLayout;
 
 
       protected override void CreateChildElements()
       {
           base.CreateChildElements();
 
           _overallLayout = new StackLayoutPanel {Orientation = Orientation.Horizontal};
 
           _imageElement = new LightVisualElement
               {
                   DrawText = false,
                   ImageLayout = ImageLayout.Center,
                   StretchVertically = false,
                   Margin = new Padding(10, 22, 10, 5),
                   NotifyParentOnMouseInput = true,
                   ShouldHandleMouseInput = false
               };
 
           _overallLayout.Children.Add(_imageElement);
 
           _textLayout = new StackLayoutPanel { Orientation = Orientation.Vertical };
            
           _overallLayout.Children.Add(_textLayout);
 
           _nameElement = new LightVisualElement
               {
                   TextAlignment = ContentAlignment.MiddleLeft,
                   Margin = new Padding(10, 10, 10, 5),
                   Font = new Font("Segoe UI", 12, FontStyle.Bold, GraphicsUnit.Point),
                   NotifyParentOnMouseInput = true,
                   ShouldHandleMouseInput = false
               };
 
           _textLayout.Children.Add(_nameElement);
 
           _descriptionElement = new LightVisualElement
           {
               TextAlignment = ContentAlignment.MiddleLeft,
               Margin = new Padding(10, 5, 10, 5),
               Font = new Font("Segoe UI", 12, FontStyle.Bold, GraphicsUnit.Point),
               NotifyParentOnMouseInput = true,
               ShouldHandleMouseInput = false
           };
 
           _textLayout.Children.Add(_descriptionElement);
 
           _waitingBarElement= new RadWaitingBarElement();
           _waitingBarElement.WaitingBarOrientation = Orientation.Horizontal;
           _waitingBarElement.WaitingDirection = ProgressOrientation.Right;
           _waitingBarElement.Size = new Size(120, 14);
           _waitingBarElement.WaitingIndicatorSize = new Size(50, 30);
           _waitingBarElement.WaitingSpeed = 90;
           _waitingBarElement.WaitingStep = 2;
           _waitingBarElement.WaitingStyle = WaitingBarStyles.Dash;
           //_waitingBarElement.Visibility = ElementVisibility.Collapsed;
           _waitingBarElement.StartWaiting();
           _textLayout.Children.Add(_waitingBarElement);
 
           Children.Add(_overallLayout);
           Padding = new Padding(10);
           Margin = new Padding(4, 2, 4, 2);
           Shape = new RoundRectShape(5);
           DrawBorder = true;
           DrawFill = true;
 
           BorderInnerColor = SystemColors.ControlLightLight;
           BorderInnerColor2 = SystemColors.Control;
           BorderInnerColor3 = SystemColors.ControlDark;
           BorderInnerColor4 = SystemColors.ControlDarkDark;
           BorderGradientStyle = GradientStyles.Solid;
           BorderBottomColor = SystemColors.ControlDark;
           BorderLeftColor = SystemColors.ControlDark;
           BorderTopColor = SystemColors.ControlDark;
           BorderRightColor = SystemColors.ControlDark;
           BorderGradientAngle = 270;
           BorderGradientStyle = GradientStyles.Solid;
 
           BackColor = SystemColors.Window;
           BackColor2 = SystemColors.Control;
           BackColor3 = SystemColors.ControlDark;
           BackColor4 = SystemColors.ControlLightLight;
           GradientAngle = 90;
           GradientPercentage = (float) 0.5;
           GradientPercentage2 = (float) 0.666;
           GradientStyle = GradientStyles.Linear;
           NumberOfColors = 2;
           SmoothingMode = SmoothingMode.AntiAlias;
 
       }
 
       protected override void OnMouseEnter(EventArgs e)
       {
           base.OnMouseEnter(e);
           BorderInnerColor = SystemColors.ControlLightLight;
           BorderInnerColor2 = SystemColors.Control;
           BorderInnerColor3 = SystemColors.ControlDark;
           BorderInnerColor4 = SystemColors.ControlDarkDark;
           BorderGradientStyle = GradientStyles.Solid;
           BorderBottomColor = SystemColors.ControlDark;
           BorderLeftColor = SystemColors.ControlDark;
           BorderTopColor = SystemColors.ControlDark;
           BorderRightColor = SystemColors.ControlDark;
           BorderGradientAngle = 90;
           BorderGradientStyle = GradientStyles.Linear;
 
           BackColor = SystemColors.Window;
           BackColor2 = SystemColors.Control;
           BackColor3 = SystemColors.ControlDark;
           BackColor4 = SystemColors.ControlLightLight;
           GradientAngle = 90;
           GradientPercentage = (float)0.5;
           GradientPercentage2 = (float)0.666;
           GradientStyle = GradientStyles.Linear;
           NumberOfColors = 3;
           SmoothingMode = SmoothingMode.AntiAlias;
       }
 
       protected override void OnMouseLeave(EventArgs e)
       {
           base.OnMouseLeave(e);
           BorderInnerColor = SystemColors.ControlLightLight;
           BorderInnerColor2 = SystemColors.Control;
           BorderInnerColor3 = SystemColors.ControlDark;
           BorderInnerColor4 = SystemColors.ControlDarkDark;
           BorderGradientStyle = GradientStyles.Solid;
           BorderBottomColor = SystemColors.ControlDark;
           BorderLeftColor = SystemColors.ControlDark;
           BorderTopColor = SystemColors.ControlDark;
           BorderRightColor = SystemColors.ControlDark;
           BorderGradientAngle = 270;
           BorderGradientStyle = GradientStyles.Solid;
 
           BackColor = SystemColors.Window;
           BackColor2 = SystemColors.Control;
           BackColor3 = SystemColors.ControlDark;
           BackColor4 = SystemColors.ControlLightLight;
           GradientAngle = 90;
           GradientPercentage = (float)0.5;
           GradientPercentage2 = (float)0.666;
           GradientStyle = GradientStyles.Linear;
           NumberOfColors = 2;
           SmoothingMode = SmoothingMode.AntiAlias;
       }
 
       protected override void SynchronizeProperties()
       {
           _imageElement.Image = (Image)Data["Image"];
           _nameElement.Text = Convert.ToString(Data["Name"]);
           _descriptionElement.Text = Convert.ToString(Data["Description"]);
       }         
        
       protected override SizeF MeasureOverride(SizeF availableSize)
       {
           var measuredSize = base.MeasureOverride(availableSize);
           _overallLayout.Measure(measuredSize);
           return measuredSize;
       }         
        
       protected override SizeF ArrangeOverride(SizeF finalSize)
       {
           base.ArrangeOverride(finalSize);
           _overallLayout.Arrange(new RectangleF(PointF.Empty, finalSize));
           return finalSize;
       }
 
                   
   }

private void LvViewsItemMouseClick(object sender, ListViewItemEventArgs e)
{
    if (_resultsTable==null)
        _resultsTable = StrategyBacktestLoader.getBacktestResults(frmParadigmFM.Authority, ThisParent.StrategyID, ThisParent.ID,
                                                                  ThisVariation.ID);
 
    var element = sender as RadCustomVariationViewVisualItem;
 
    var view = (BacktestViewType) e.Item.Tag;
    DisplayBacktestView(view);
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 13 Mar 2013, 02:26 PM
Hello Ian,

Thank you for writing.

To access the waiting bar element you can expose a property in your custom item element. Then in the ItemMouseClick event handler you can use the following line to get the element you have clicked on and start its waiting bar:
RadCustomVariationViewVisualItem element = e.ListViewElement.ViewElement.GetElement(e.Item) as RadCustomVariationViewVisualItem;
 
if (element != null)
{
    element.WaitingbarElement.Visibility = ElementVisibility.Visible;
    element.WaitingbarElement.StartWaiting();
}

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

Regards,
Ivan Petrov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Ian
Top achievements
Rank 1
answered on 14 Mar 2013, 04:49 AM
That's got it thanks!
Tags
ListView
Asked by
Ian
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Ian
Top achievements
Rank 1
Share this question
or