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

[Solved] RadDataGrid - 2 way binding / selection

2 Answers 108 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Santiago
Top achievements
Rank 1
Santiago asked on 28 May 2014, 07:50 AM
I'm trying to
1. Have Inline edits affect the datasource
2. display selected item on external control i.e. textbox.

The response to binding-to-value-outside-of-datatemplate
http://www.telerik.com/clientsfiles/28ad42cd-f28e-47e3-b816-c75eb6ab05bd_ModifyingTheDataClass.zip?sfvrsn=0

Fits closest to the structure of what I'm trying to get done.

Use case:
So I want to select the 6th line, change the word from "text" to "text2", have the changes save after pressing enter, and have the textbox display the text of whatever I currently have selected.

I hope that is possible within the framework.

2 Answers, 1 is accepted

Sort by
0
Santiago
Top achievements
Rank 1
answered on 28 May 2014, 08:00 AM
I figured out the first part to my question:

    <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <telerikGrid:RadDataGrid x:Name="testGrid" ItemsSource="{Binding Items, Mode=TwoWay}" AutoGenerateColumns="False" UserEditMode="Inline">
            <telerikGrid:RadDataGrid.Columns>
                <telerikGrid:DataGridTextColumn Header="Text" PropertyName="Text"/>
                <telerikGrid:DataGridNumericalColumn Header="Value" PropertyName="Value"/>
            </telerikGrid:RadDataGrid.Columns>
        </telerikGrid:RadDataGrid>
        <TextBox Text="{Binding ElementName=testGrid,Path=SelectedItem.Text, Mode=TwoWay}"/>
    </StackPanel>

The ElementName binding displays the text of whatever I currently have selected, but I still need help figuring out how to save inline edits.


0
Santiago
Top achievements
Rank 1
answered on 28 May 2014, 06:16 PM
So I'm answering my own question, but here is the solution.  I'm not entirely sure what I did wrong in my original example, but I went back and simplified it as much as possible.

MainPage.xaml
<Page
    xmlns:local="using:TelerikGridTest"
    xmlns:Grid="using:Telerik.UI.Xaml.Controls.Grid"
    x:Class="TelerikGridTest.MainPage"
    mc:Ignorable="d">
 
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid:RadDataGrid x:Name="DataGrid" HorizontalAlignment="Left" Margin="10,86,0,0" VerticalAlignment="Top" Height="682" Width="1346" UserFilterMode="Disabled" UserGroupMode="Disabled" UserSortMode="Multiple" UserEditMode="Inline" AlternationStep="1"/>
        <TextBox HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding ElementName=DataGrid,Path=SelectedItem.Country, Mode=TwoWay}" VerticalAlignment="Top" Height="71" Width="1346"/>
    </Grid>
</Page>

MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
 
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
 
namespace TelerikGridTest
{
    public class Data
    {
        public string Country
        {
            get;
            set;
        }
        public string Capital
        {
            get;
            set;
        }
    }
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.DataGrid.ItemsSource = new List<Data>
                                     {
                                         new Data { Country = "India", Capital = "New Delhi"},
                                         new Data { Country = "South Africa", Capital = "Cape Town"},
                                         new Data { Country = "Nigeria", Capital = "Abuja" },
                                         new Data { Country = "Singapore", Capital = "Singapore" }                            
                                     };
        }
    }
}

The binding ended up working pretty easily, I think there is something in the viewmodel example I gave before that is intercepting the binding from happening properly, always resets it to text.  I was able to modify the radgrid editing example to also work this way which also uses a viewmodel.  I'll eventually figure that out, but for now this will do.
Tags
Grid for XAML
Asked by
Santiago
Top achievements
Rank 1
Answers by
Santiago
Top achievements
Rank 1
Share this question
or