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

Bind DataForm to radTreeView and save edits

1 Answer 94 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
CD
Top achievements
Rank 1
CD asked on 18 Jul 2011, 07:25 PM
Hello

I have my Treeview setup to load on demand:

<DataTemplate x:Name="Sub_SubLevel2"
              x:Key="DetailTemplate">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Product ID: " />
        <TextBlock Text="{Binding ProductID}" />
    </StackPanel>
</DataTemplate>
<telerik:HierarchicalDataTemplate x:Name="SubLevel"
                                  x:Key="OrderTemplate"
                                  ItemsSource="{Binding Order_Details}"
                                  ItemTemplate="{StaticResource DetailTemplate}">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Order ID: " />
        <TextBlock Text="{Binding OrderID}" />
    </StackPanel>
</telerik:HierarchicalDataTemplate>
<telerik:HierarchicalDataTemplate x:Name="Root"
                                  x:Key="CustomerTemplate"
                                  ItemsSource="{Binding Orders}"
                                  ItemTemplate="{StaticResource OrderTemplate}">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Customer ID: " />
        <TextBlock Text="{Binding CustomerID}" />
    </StackPanel>
</telerik:HierarchicalDataTemplate>
<telerik:RadTreeView Background="WhiteSmoke"
                     Name="radTreeView1"
                     ItemTemplate="{StaticResource CustomerTemplate}"
                     ItemPrepared="radTreeView_ItemPrepared"
                     IsLoadOnDemandEnabled="True"
                     IsExpandOnSingleClickEnabled="True"
                     LoadOnDemand="radTreeView_LoadOnDemand" 
                     />

and then it is populated in code-behind:

this.radTreeView1.ItemsSource = _Context.Customers;
var loadTree = _Context.Load(_Context.GetCustomersQuery(), LoadBehavior.RefreshCurrent, true);

I bind the dataform to the tree:
<telerik:RadDataForm x:Name="radDataForm"
                     Header="Title"
                     Grid.Column="1"
                     CurrentItem="{Binding Path=SelectedItem, ElementName=radTreeView1}" />

When I run, it works as expected with the dataform showing the detail for the item selected in the tree.

Save Edits (not working)
private void radDataForm_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
{
    radDataForm.CommitEdit(true);
    _Context.SubmitChanges(so =>
    {
        string errorMsg = string.Empty;
        if (so.HasError)
        {
            errorMsg = "failed";
        }
        else
        {
            errorMsg = "succeeded";
        }
        MessageBox.Show("Update " + errorMsg);
    }, null);
}


I would like to be able to edit in the dataform, and submit the changes back to the database. Is there an example on how to do this?


Thank you.

1 Answer, 1 is accepted

Sort by
0
CD
Top achievements
Rank 1
answered on 19 Jul 2011, 05:33 PM
I believe my issue is with the DataForm validation. I am going to start another thread with a new topic.
Thanks.
Tags
DataForm
Asked by
CD
Top achievements
Rank 1
Answers by
CD
Top achievements
Rank 1
Share this question
or