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

[Solved] RadGridViewCommands.BeginInsert and wcf ria services

11 Answers 392 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ole
Top achievements
Rank 1
Ole asked on 02 Sep 2010, 05:37 PM
Hi,

I am using a radgridview control and binding it via c# code like this....

<navigation:Page xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  x:Class="PriceBank.Views.ChapterSetup" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
  
           d:DesignWidth="640" d:DesignHeight="480"
           Title="ChapterSetup Page">
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition />
        </Grid.RowDefinitions>
  
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,0">
            <telerik:RadButton Width="150" Content="Delete selected rows" Margin="0,0,5,0" 
                               Command="telerikGrid:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
            <telerik:RadButton Width="150" Content="Add new row" Margin="0,0,5,0" 
                               Command="telerikGrid:RadGridViewCommands.BeginInsert" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
            <telerik:RadButton Width="150" Content="Save insert/edit" Margin="0,0,5,0"
                               Command="telerikGrid:RadGridViewCommands.CommitEdit" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
            <telerik:RadButton Width="150" Content="Cancel insert/edit"
                               Command="telerikGrid:RadGridViewCommands.CancelRowEdit" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
        </StackPanel>
  
        <telerik:RadGridView  x:Name="CostPlanInfoGridView" AutoGenerateColumns="False" SelectionMode="Extended"
                             Margin="0,5,0,0" Grid.Row="1">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Audkenni}" SortMemberPath="Audkenni"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Heiti}" SortMemberPath="Heiti"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Heiti_E}" SortMemberPath="Heiti_E"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Hofundur}" SortMemberPath="Hofundur"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Verkkaupi}" SortMemberPath="Verkkaupi"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Stofndagur}" SortMemberPath="Stofndagur"></telerik:GridViewDataColumn>
                <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Template}"></telerik:GridViewCheckBoxColumn>
                <telerik:GridViewComboBoxColumn></telerik:GridViewComboBoxColumn>
            </telerik:RadGridView.Columns>
             
        </telerik:RadGridView>
    </Grid>
</navigation:Page>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using PriceBank.Web.Services;
using Telerik.Windows.Controls;
  
namespace PriceBank.Views
{
     
    public partial class ChapterSetup : Page
    {
        BuildingCostDomainContext basicContext;
        public ChapterSetup()
        {
  
            ICommand deleteCommand = RadGridViewCommands.Delete;
            ICommand beginInsertCommand = RadGridViewCommands.BeginInsert;
            ICommand cancelRowEditCommand = RadGridViewCommands.CancelRowEdit;
            ICommand commitEditCommand = RadGridViewCommands.CommitEdit;
  
            InitializeComponent();
            basicContext = new BuildingCostDomainContext();
            CostPlanInfoGridView.ItemsSource = basicContext.tbl_KostAaetluns;
            basicContext.Load(basicContext.GetTbl_KostAaetlunQuery());
             
        }
  
        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
  
    }
}

The grid gets loaded with data but the add button does not work. I click it but nothing happens.  Can someone pls. help to get this function running.

Thanks

Ole

11 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Sep 2010, 06:58 AM
Hi,

 Can you provide more info about basicContext.tbl_KostAaetluns? If this is not at least IList the grid will unable to add items. 

Regards,
Vlad
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Ole
Top achievements
Rank 1
answered on 03 Sep 2010, 10:07 AM
Hi,

The code for basicContext.tbl_KostAaetluns is auto generate code based edmx model + added domain service.

System.ServiceModel.DomainServices.Client.EntitySet<tbl_KostAetlun> is the type for tbl_KostAaetluns.

Best regards

Ole








0
Vlad
Telerik team
answered on 03 Sep 2010, 10:08 AM
Hi ,

 Why not use DomainDataSource instead?

All the best,
Vlad
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Ole
Top achievements
Rank 1
answered on 06 Sep 2010, 04:43 PM
Hi,

Put in  a domain source and the add button appered thanks,

How ever the save button does not work, I dont even reach the update and insert methodes in my domain service.

Also I have reached a dead end in getting a radcombobox to work within a datatemplate in a details view.

I can not get it to display what has been already selected using selected value. I am databinding both itemsource and selected value.

The Itemsource works and I can select values. I can see that the key is getting bound , due to I have text field next to the combobox bound to the value.

Any help is appriciated ? Thanks

Ole

<navigation:Page xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  x:Class="PriceBank.Views.ChapterSetup" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           mc:Ignorable="d"
           xmlns:local="clr-namespace:PriceBank"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
             xmlns:my="clr-namespace:PriceBank.Web.Services" 
           d:DesignWidth="640" d:DesignHeight="480"
           Title="ChapterSetup Page" xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices">
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
        <RowDefinition Height="27" />
        <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.Resources>
            <local:PriceAreaListProvider x:Key="priceAreaListProvider" />
        </Grid.Resources>
  
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,0">
            <telerik:RadButton Width="150" Content="Delete selected rows" Margin="0,0,5,0" 
                               Command="telerikGrid:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
            <telerik:RadButton Width="150" Content="Add new row" Margin="0,0,5,0" 
                               Command="telerikGrid:RadGridViewCommands.BeginInsert" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
            <telerik:RadButton Width="150" Content="Save insert/edit" Margin="0,0,5,0"
                               Command="telerikGrid:RadGridViewCommands.CommitEdit" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
            <telerik:RadButton Width="150" Content="Cancel insert/edit"
                               Command="telerikGrid:RadGridViewCommands.CancelRowEdit" CommandTarget="{Binding ElementName=CostPlanInfoGridView}"  />
        </StackPanel>
              
        <telerik:RadGridView  x:Name="CostPlanInfoGridView" AutoGenerateColumns="False" SelectionMode="Extended"
                             Margin="0,5,0,0" Grid.Row="1" ItemsSource="{Binding ElementName=DomainDataSourceChapterSettings, Path=Data}" RowDetailsVisibilityChanged="CostPlanInfoGridView_RowDetailsVisibilityChanged">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn></telerik:GridViewToggleRowDetailsColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Audkenni}" SortMemberPath="Audkenni"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Heiti}" SortMemberPath="Heiti"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Heiti_E}" SortMemberPath="Heiti_E"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Hofundur}" SortMemberPath="Hofundur"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Verkkaupi}" SortMemberPath="Verkkaupi"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Stofndagur}" SortMemberPath="Stofndagur"></telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding VerdSvaediID}" SortMemberPath="VerdSvaediID"></telerik:GridViewDataColumn>
                <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Template}"></telerik:GridViewCheckBoxColumn>
                 
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <Grid>
                        <StackPanel>
                            <telerik:RadComboBox  x:Name="cmbPriceArea"    ItemsSource="{Binding PriceAreaList, Source={StaticResource priceAreaListProvider}}" DisplayMemberPath="Verdsvaedi" SelectedValuePath="VerdSvaediID"  ></telerik:RadComboBox>
                            <TextBox Text="{Binding VerdSvaediID, Mode=TwoWay}"></TextBox>
  
                                                    </StackPanel>
                    </Grid>
                </DataTemplate>
                  
                  
            </telerik:RadGridView.RowDetailsTemplate>
  
  
  
        </telerik:RadGridView>
        <riaControls:DomainDataSource  d:DesignData="{d:DesignInstance my:BuildingCostDomainContext, CreateList=true}" Height="0" LoadedData="ChapterSettingsDomainDataSource_LoadedData" Name="DomainDataSourceChapterSettings" QueryName="GetTbl_KostAaetlunQuery" Width="0" PageSize="5" >
              
            <riaControls:DomainDataSource.DomainContext>
                <my:BuildingCostDomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource >
  
          
    </Grid>
</navigation:Page>

using PriceBank.Web.Services;
using System.Collections.Generic;
using System.ServiceModel.DomainServices.Client;
using PriceBank.Views;
namespace PriceBank
{
    public class PriceAreaListProvider
    {
        BuildingCostDomainContext buildCtx;
  
        public ChapterSetup Chapter { get; set; }
  
        public BuildingCostDomainContext domainCtx
        {
            set
            {
                buildCtx = value;
              LoadOperation op =  buildCtx.Load<tbl_Verdsvaedi>(buildCtx.GetTbl_VerdsvaediQuery(), priceContextLoaded,"");                
            }
        }
  
        public EntitySet<tbl_Verdsvaedi> PriceAreaList
        {
            get
            {
                return buildCtx.tbl_Verdsvaedis;
            }
  
        }
  
        private void priceContextLoaded(LoadOperation<tbl_Verdsvaedi> efni)
        {
            Chapter.DomainDataSourceChapterSettings.Load();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using PriceBank.Web.Services;
using Telerik.Windows.Controls;
using System.Windows.Data;
  
namespace PriceBank.Views
{
     
    public partial class ChapterSetup : Page
    {
        BuildingCostDomainContext basicContext;
        public ChapterSetup()
        {
  
            ICommand deleteCommand = RadGridViewCommands.Delete;
            ICommand beginInsertCommand = RadGridViewCommands.BeginInsert;
            ICommand cancelRowEditCommand = RadGridViewCommands.CancelRowEdit;
            ICommand commitEditCommand = RadGridViewCommands.CommitEdit;
  
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ChapterSetup_Loaded);            
             
        }
  
        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void ChapterSettingsDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {
  
            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }
  
        void ChapterSetup_Loaded(object sender, RoutedEventArgs e)
        {
            basicContext = new BuildingCostDomainContext();// used for maingrid
            App.Current.Resources.Remove("webContext");
            App.Current.Resources.Add("webContext", basicContext);
            PriceAreaListProvider priceAreaListProvider = LayoutRoot.Resources["priceAreaListProvider"] as PriceAreaListProvider;
            priceAreaListProvider.Chapter = this;
            priceAreaListProvider.domainCtx = basicContext;
              
        }
        RadComboBox combobox;
        private void CostPlanInfoGridView_RowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
        {
            //combobox = e.DetailsElement.ChildrenOfType<RadComboBox>().First();
              
             
        }
  
        private void PriceAreassDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {
            //combobox.SelectedValue = new Binding("VerdSvaediID");
              
        }
  
    }
}
0
Ole
Top achievements
Rank 1
answered on 07 Sep 2010, 12:48 PM
Hi,

Investegated further, added mode = "TwoWay" in my column bindings, created a button with click event code
private void RadButton_Click(object sender, RoutedEventArgs e)
       {
             
           DomainDataSourceChapterSettings.SubmitChanges();
       }

Here I discovered that the DomainDataSourceChapterSettings.datacontext.haschanges was false, so the changes was not propergated to the domainsource.

any help pls.
Best regards

Ole
0
Accepted
Valeri Hristov
Telerik team
answered on 08 Sep 2010, 12:09 PM
Hi,

 I was unable to find the save button code - can you post it? Generally you should use SubmitChanges() method to post changes to the server. As to the combo box, you need to bind the SelectedValue property to the corresponding data property:
<telerik:RadComboBox  x:Name="cmbPriceArea"    ItemsSource="{Binding PriceAreaList, Source={StaticResource priceAreaListProvider}}" DisplayMemberPath="Verdsvaedi" SelectedValuePath="VerdSvaediID" 
SelectedValue="{Binding VerdSvaediID, Mode=TwoWay}"
></telerik:RadComboBox>

In case the data item's property that has to be changed with RadComboBox is named VerdSvaediID the code above should do the trick.

Regards,
Valeri Hristov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Ole
Top achievements
Rank 1
answered on 08 Sep 2010, 01:40 PM

Hi,

 

This did the trick for the combobox. Thanks.

 

The code behind the save btn is

 

private void RadButton_Click(object sender, RoutedEventArgs e)
       {
             
           DomainDataSourceChapterSettings.SubmitChanges();
       }

 

and putting a break point here and investigating the domainsource yields that the dds  datacontext.haschanges is false. And therefor no update takes place.

 

Thanks

 

Ole

0
Ole
Top achievements
Rank 1
answered on 10 Sep 2010, 11:51 AM
Hi,

I believe that there is a bug/ undesired behavior in the radgridview. If you go directly to click on a save button (dds.submitchanges()) after changing a cell then the dds.haschanges is false. You will have to first click somewhere else in the grid to get the dds notified about the change.

That is my current problem.

Can someone help ?...

Ole

0
Nedyalko Nikolov
Telerik team
answered on 14 Sep 2010, 08:53 AM
Hello Ole,

Indeed this sounds like a bug, but I cannot confirm that without a project that demonstrates this. Could you please send me a sample project which I can debug on my side?
Thank you in advance.

P.S. You have to open a separate support ticket in order to be able to attach a zip file.

Sincerely yours,
Nedyalko Nikolov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Berthold
Top achievements
Rank 1
answered on 31 Jan 2011, 03:36 PM
Hi,

I've the same problem - after changing a cell and click direktly on a filter (I use serverside filtering) I got an error, since there are pending changes. Before I do the filtering, I check my DomainDataSource object for changes (HasChanges) which is false!
It seems the update of the DomainDataSource.HasChanges-Flag (from false --> true) comes after the click event is handled.
 
Is there any solution for that?

Thanks
Berthold 
0
Nedyalko Nikolov
Telerik team
answered on 01 Feb 2011, 04:37 PM
Hello Berthold,

When you changing a cell and then click anywhere outside the grid the edited cell loses focus which triggers commit edit procedure (according to radGridView.ActionOnLostFocus value which by default is set to CommitEdit) which changes DomainDataSource.HasChanges from false to true. You could set radGridView.ActionOnLostFocus to CancelEdit and everything should work fine.
Let me know if this doesn't help.

Greetings,
Nedyalko Nikolov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Ole
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Ole
Top achievements
Rank 1
Valeri Hristov
Telerik team
Nedyalko Nikolov
Telerik team
Berthold
Top achievements
Rank 1
Share this question
or