Set shape name by UI in RadDiagram

1 Answer 23 Views
Diagram, DiagramRibbonBar, DiagramToolBox
Marian
Top achievements
Rank 1
Marian asked on 28 Nov 2021, 08:47 PM

Hello,

is it possible to set shape name by UI? I don't see name in Settings Pane. Or can I somehow customize Settings Pane to edit name of shape?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Dec 2021, 10:36 AM
Hello, Marian, 

If you need to edit the shape's text at run time, note that RadDiagram gives you the ability to edit the content of its items. You can double-click items in order to edit them:

Just make sure that the editing is enabled:

this.radDiagram1.IsEditable = true;

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Marian
Top achievements
Rank 1
commented on 01 Dec 2021, 10:55 AM

Hello,

I known you can edit shape text, it's also in SettinsgPane. My question was about shape name, not text.  Purpose is to edit diagram template, set names for specific shapes, and then display texts in this shapes in production program. I know I can set shape text to $Variable1 in designer program and then programatically find all texts starting with $ and write them to names after loading diagram in production program, but best will be if user can edit shape name directly in designer program.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 01 Dec 2021, 01:10 PM

Hello, Marian, 

Thank you for the clarification. 

The RadDiagramShape.Name property is not intended to be used. That is why there is no appropriate UI for changing its value like for the Text property for example. However, it is possible to customize the settings pane and add an option next to the Text for the Name property. Please refer to the sample code snippet below: 

        public RadForm1()
        {
            InitializeComponent();
            RadDiagramSettingsPane settingsPane = this.radDiagram1.DiagramElement.SettingsPane; 
            RadTextBox tb = new RadTextBox();
            tb.Width = settingsPane.RadTextBoxItemText.Width;
            tb.NullText = "Name";
            tb.Location = new Point(settingsPane.RadTextBoxItemText.Location.X,settingsPane.RadTextBoxItemText.Location.Y + 30);
            tb.TextChanged += tb_TextChanged;
            foreach (Control c in settingsPane.RadPageViewPageText.Controls)
            {
                if (c != settingsPane.RadTextBoxItemText)
                {
                    c.Top += 30;
                }
            }
            settingsPane.RadPageViewPageText.Controls.Add(tb);
        }

        private void tb_TextChanged(object sender, EventArgs e)
        {
            if (this.radDiagram1.SelectedItem != null)
            {
                RadDiagramShape shape = this.radDiagram1.SelectedItem as RadDiagramShape;
                shape.Name = ((RadTextBox)sender).Text;
            }
        }

I believe that it would fit your custom requirement.

Marian
Top achievements
Rank 1
commented on 02 Dec 2021, 08:41 AM

Hello,

thanks, I will try. If Name property is not intended to be used, what's the best way to do this? How can I identify some specific shape without this?

One more question, what's the difference between Shapes and Items collection in RadDiagram? Can diagram have some items that are not shapes?

Dess | Tech Support Engineer, Principal
Telerik team
commented on 02 Dec 2021, 09:45 AM

Hello, Marian, 

The Shapes collection is intended to give you only the shapes, while the Items collection contains the connections between the shapes as well.

As to case with accessing specific shapes, please have in mind that the Shapes collection offers only accessing by index. Hence, you will need to iterate the collection and find the item with the exact Name. I have prepared a sample code snippet for your reference:

        private void button1_Click(object sender, EventArgs e)
        {
            var shape = GetShapeByName("test");
        }

        private object GetShapeByName(string name)
        {
            foreach (RadDiagramShape s in this.radDiagram1.Shapes)
            {
                if (s.Name==name)
                {
                    return s;
                }
            }
            return null;
        }

Marian
Top achievements
Rank 1
commented on 02 Dec 2021, 09:53 AM

Thanks. Of course, I know how to find shape with requested Name (I would use LINQ Where). I was responding to your info that Name was not intended to use. So my question was how to do it without using Name property.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 02 Dec 2021, 09:59 AM

Hi, Marian,

RadDiagram doesn't offer such kind of accessing its shapes. It is possible either to use the Shapes[index] approach or traverse the collection and look for the desired Name. Feel free to use this approach which suits your scenario best.

Tags
Diagram, DiagramRibbonBar, DiagramToolBox
Asked by
Marian
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or