Accessing child elements of a Custom ListView Item

3 posts, 1 answers
  1. Ian
    Ian avatar
    61 posts
    Member since:
    Jul 2010

    Posted 11 Mar 2013 Link to this post

    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. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 13 Mar 2013 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ian
    Ian avatar
    61 posts
    Member since:
    Jul 2010

    Posted 13 Mar 2013 Link to this post

    That's got it thanks!
Back to Top