DiagramListViewVisualItem unique ID

4 posts, 0 answers
  1. Sina
    Sina avatar
    13 posts
    Member since:
    Jan 2011

    Posted 19 Jun 2017 Link to this post

    Hi,

    I defined DiagramListViewVisualItem item and dragged it to the radDiagram. 

    My question is how to find the items by ID? 

    When I found the IDs, I would connect two items programmatically. <Source and target are known>.

    I used this code

     MessageBox.Show(radDiagram1.Shapes[0].Name.ToString());

    but nothing ...

    But when I used this code

    MessageBox.Show(radDiagram1.Shapes[0].Width.ToString());

    the width was shown!

    I need to find the items individually. 

    Thank you

     

  2. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 20 Jun 2017 Link to this post

    Hello Sina,

    First, you ned to set the name when the item is added:
    public RadForm1()
    {
        InitializeComponent();
     
        radDiagram1.ItemsChanged += RadDiagram1_ItemsChanged;
    }
    int count = 0;
    private void RadDiagram1_ItemsChanged(object sender, Telerik.WinControls.UI.Diagrams.DiagramItemsChangedEventArgs e)
    {
        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
        {
            var shape = e.NewItems.ToList()[0] as RadDiagramShape;
            if (shape != null)
            {
                shape.Name = "Item" + count++;
            }
     
        }
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        foreach (var item in radDiagram1.Items)
        {
            Console.WriteLine(item.Name);
        }
    }

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Sina
    Sina avatar
    13 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2017 in reply to Dimitar Link to this post

    Hi Dimitar,

     

    Thank you for your comment.

    The way you suggested works very well but I cannot find which item was added to the diagram, so I changed it a bit as follows:

    ************************************************************

     

    this.radDiagramToolbox1.ListViewElement.DragDropService.PreviewDragDrop += DragDropService_PreviewDragDrop;

     

    int count2 = 0;

            private void DragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
            {
                DiagramListViewVisualItem dragItem = e.DragInstance as DiagramListViewVisualItem;
                RadDiagramElement dropTarget = e.HitTarget as RadDiagramElement;
                if (dragItem != null && dropTarget != null && dragItem.Data.Key == "Unit")
                {
                    e.Handled = true;
                    RadDiagramShape shape = dropTarget.Shapes.Last() as RadDiagramShape;
                    //shape.DiagramShapeElement.Shape = null;
                    //shape.BackColor = Color.Transparent;
                    //shape.DiagramShapeElement.Image = dragItem.Image;
                    //shape.DiagramShapeElement.ImageLayout = dragItem.ImageLayout;

                    shape.Name = "Unit No. " + count2++;

                };
            }

    ******************************************************

    In this case, I can find which item is seleted then an Id is assigned. 

    Thank you very much. 

  4. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 21 Jun 2017 Link to this post

    Hi Sina,

    I am glad that you have found a solution. Do not hesitate to contact us if you have other questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top