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

while editing treeview,if I give duplicate name it should return oldname

6 Answers 163 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Runjith
Top achievements
Rank 2
Runjith asked on 29 May 2015, 12:06 PM

while editing treeview,if I Edit(give) duplicate name it should return oldname for selected node. 

please help me how to fix.

Regards,

Ranjith

 

 

6 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 01 Jun 2015, 04:15 PM
Hello Ranjith,

Depending on your scenario I can suggest you couple approaches for achieving this:
  • If you are populating the RadTreeView control with RadTreeViewItems statically in XAML you can use the tree's PreviewEdited event. Here is an example:
    private void RadTreeView_PreviewEdited(object sender, RadTreeViewItemEditedEventArgs e)
    {
        var treeViewItem = e.OriginalSource as RadTreeViewItem;
     
        if (another node in the tree contains the same name as the name of the edited item) // you can use the e.NewValue to get the edited name and see if it matches with another name in the tree
        {
            e.Handled = true;
            treeViewItem.IsInEditMode = false;
            treeViewItem.Focus();
        }
    }
  • If you use the treeview in a data binding scenario you can use the EventToCommandBehavior and ICommands in your view model to check for a valid value. For your convenience I prepared a sample project demonstrating this approach. Please take a look at it and let me know if it helps.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Runjith
Top achievements
Rank 2
answered on 02 Jun 2015, 07:02 AM

Hello Martin,

My TreeView contains "Session","Session (1)","session (2)"...etc...

For example I am going to edit "Session (1)" item as "Session" it should take oldame("Session (1)".why because alrady I have "Session".As per your code "var treeViewItem = e.OriginalSource as RadTreeViewItem;"

e.OriginalSource gives Edited Name("Session") it should return "Session (1)".

if I call like "var treeViewItem = e.OldValue as RadTreeViewItem;" ,treeViewItem returns null.

and also please find the attaches files also. Please help me how to proceed this.

0
Runjith
Top achievements
Rank 2
answered on 02 Jun 2015, 07:12 AM
Else If I edit as "Session", the TreeViewItem should be on edit Mode.
0
Martin Ivanov
Telerik team
answered on 02 Jun 2015, 08:34 AM
Hello Ranjith,

The RadTreeViewItem's header (name) is already changed in the Edited event, so you cannot use it to get the old value. About the e.OldValue - it returns null because the property contains string, but not RadTreeViewItem object. Furthermore, the property contains the header of the item before the edit and you can use it for your implementation.
private tv_PreviewEdited(object sender, RadTreeViewItemEditedEventArgs e)
{
    if (tv.SelectedItem.ToString() == "Session")
    {
        var oldName = e.OldValue.ToString();
....
    }
}
Also, if you don't want to exit the edit mode when the value is not valid you can use only the e.Handled property in the PreviewEdited event handler. This won't commit the changes and you won't need to use the old value.
private tv_PreviewEdited(object sender, RadTreeViewItemEditedEventArgs e)
{
    if (tv.SelectedItem.ToString() == "Session")
    {
        e.Handled = true;
    }
}

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Runjith
Top achievements
Rank 2
answered on 02 Jun 2015, 10:04 AM

private tv_PreviewEdited(object sender, RadTreeViewItemEditedEventArgs e){    if (tv.SelectedItem.ToString() == "Session") 

   { 

string _str = "Plese select different name!";

 Utils.ShowErrorMessage(_str, true, "Warning!!!!!");

  e.Handled = true;
  ....}

popup window opens and if I select ok, and The selected node(RadTreeViewItem) should be editable mode.(Just It was selected mode only)

Now I am trying that, but its not happening.

Please help me.

 

0
Martin Ivanov
Telerik team
answered on 03 Jun 2015, 10:44 AM
Hello,

I tested the reported scenario and the treeview item does not exit the edit mode when a popup window opens. Can you please take a look at the attached project and let me know if I am missing something?

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
Runjith
Top achievements
Rank 2
Answers by
Martin Ivanov
Telerik team
Runjith
Top achievements
Rank 2
Share this question
or