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

DiagramListViewVisualItem unique ID

3 Answers 57 Views
Diagram, DiagramRibbonBar, DiagramToolBox
This is a migrated thread and some comments may be shown as answers.
Sina
Top achievements
Rank 1
Sina asked on 20 Jun 2017, 04:18 AM

Hi,

I defined  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

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 20 Jun 2017, 09:40 AM
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.
0
Sina
Top achievements
Rank 1
answered on 21 Jun 2017, 04:47 AM

 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. 

0
Dimitar
Telerik team
answered on 21 Jun 2017, 08:35 AM
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.
Tags
Diagram, DiagramRibbonBar, DiagramToolBox
Asked by
Sina
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Sina
Top achievements
Rank 1
Share this question
or