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

7 posts, 0 answers
  1. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 29 May 2015 Link to this post

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

    please help me how to fix.

    Regards,

    Ranjith

     

     

  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 01 Jun 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 02 Jun 2015 in reply to Martin Link to this post

    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.

  5. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 02 Jun 2015 in reply to Runjith Link to this post

    Else If I edit as "Session", the TreeViewItem should be on edit Mode.
  6. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 02 Jun 2015 Link to this post

    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
  7. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 02 Jun 2015 in reply to Martin Link to this post

    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.

     

  8. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 03 Jun 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready