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

[Solved] IsEditable and Databinding

5 Answers 171 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jarred Froman
Top achievements
Rank 1
Jarred Froman asked on 15 May 2009, 09:36 PM
I am using databinding on the treeview with a HierarchicalDataTemplate and the editing portion to bind to the proper property, however, it seems to be using the ToString.  Is there way to explicitly bind to a specific property on the object?

<msTreeView:HierarchicalDataTemplate x:Key="DocumentationTopics" ItemTemplate="{StaticResource DocumentationHeadings}" 
                                       ItemsSource="{Binding Path=DocumentationHeadings}">  
        <TextBlock Text="{Binding Name, Mode=TwoWay}" FontWeight="Bold" /> 
</msTreeView:HierarchicalDataTemplate> 
 

Thank You,
Jarred Froman

 

 

 

 

 


 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 16 May 2009, 06:15 AM
Hello Jarred Froman,

No, it currently supports only the ToString() method of the data class. You can override the ToString method of your data bound object to construct the string you need.

Is this going to work for you?

Sincerely yours,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jarred Froman
Top achievements
Rank 1
answered on 17 May 2009, 03:33 PM
That would defeat the idea of making it editable, no?  The idea behind making it editable is so that the desired property can be changed and if it's just reading the ToString method off of the object, this wouldn't be possible.

I gave it a try anyway and while it reads the propery in the edit box, the value still remains unchanged when coming out of edit mode.

Jarred Froman
0
Valentin.Stoychev
Telerik team
answered on 18 May 2009, 05:07 AM
Hello Jarred Froman,

You need also to handle the Edited event and to change the property with the new value that is returned from the editing. Sorry that I didn't mentioned that in the previous reply.

Please let us know if you have other problems with that.

Sincerely yours,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jarred Froman
Top achievements
Rank 1
answered on 19 May 2009, 04:26 PM
Hi Valentin,

Using your suggestion along with creating a custom property on the treeview, I am able to properly bind and have my field updated.  However, this is assuming that all levels of my tree bind to the same property on my bound objects.  Are there any plans to add in an EditingTemplate so we can define our own editors or at the very least, a property on the HierarchicalDataTemplate to specify an editingmemberpath for editing?

Also, there is a slight bug when you are editing... when you edit, if the text on the tree node is longer than that in the textbox editor, it shows through eliminating the illusion that you are actually editing the item within the tree itself.

Thanks,
-Jarred Froman
0
Jarred Froman
Top achievements
Rank 1
answered on 19 May 2009, 07:21 PM
For those interested... here is the solution I came up with for extending the treeview to allow the databinding to work with editing:

public class MyHierarchicalDataTemplate : HierarchicalDataTemplate  
{  
    public string EditingMemberPath { getset; }  
}  
 
public class MyTreeView : RadTreeView  
{  
    public MyTreeView()  
    {  
        Edited += MyTreeView_Edited;  
    }  
 
    void MyTreeView_Edited(object sender, RadTreeViewItemEditedEventArgs e)  
    {  
        var treeItem = e.Source as RadTreeViewItem;  
        if (treeItem == nullreturn;  
 
        var headerTemplate = treeItem.HeaderTemplate as MyHierarchicalDataTemplate;  
        if (headerTemplate == nullreturn;  
 
        if (string.IsNullOrEmpty(headerTemplate.EditingMemberPath)) return;  
 
        var treeItemValue = treeItem.Item;  
        var prop = treeItemValue.GetType().GetProperty(headerTemplate.EditingMemberPath);  
        if (prop == null)  
            return;  
 
        prop.SetValue(treeItemValue, e.NewText, null);  
    }  
}  
 

<Client:MyHierarchicalDataTemplate x:Key="DocumentationTopics" ItemTemplate="{StaticResource DocumentationHeadings}" 
                                   ItemsSource="{Binding Path=DocumentationHeadings}" EditingMemberPath="Name">  
    <StackPanel> 
        <TextBlock Text="{Binding Name, Mode=TwoWay}" FontWeight="Bold" /> 
    </StackPanel> 
</Client:MyHierarchicalDataTemplate> 

Jarred Froman
Tags
TreeView
Asked by
Jarred Froman
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Jarred Froman
Top achievements
Rank 1
Share this question
or