1 Answer, 1 is accepted
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.
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.
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.
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?
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;
}
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.