This question is locked. New answers and comments are not allowed.
Hi everyone,
I am having some doubts about how to bind some data to a RadGridView with two cascading combobox column's from a Domain Data Source.
This is my xaml mainpage code:
<UserControl x:Class="TesteProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:my="clr-namespace:TesteProject.Web"
xmlns:my2="clr-namespace:TesteProject">
<Grid x:Name="LayoutRoot">
<telerik:RadGridView Name="radGridView1" AutoGenerateColumns="False" EditTriggers="CellClick">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="CorrelationCode" UniqueName="CorrelationCode" DataMemberBinding="{Binding CorrelationCode}" />
<telerik:GridViewComboBoxColumn x:Name="Legacy" Header="Legacy" HeaderTextAlignment="Center"
DataMemberBinding="{Binding LegacyCode, Mode=TwoWay}" DisplayMemberPath="LegacyDescription" SelectedValueMemberPath="LegacyCode" Width="120" UniqueName="Legacy" >
</telerik:GridViewComboBoxColumn>
<telerik:GridViewComboBoxColumn x:Name="CorrelationGroup" Header="Correlation Group Code" HeaderTextAlignment="Center" ItemsSource="{StaticResource AvailableCorrelationGroups}"
DataMemberBinding="{Binding CorrelationGroupCode, Mode=TwoWay}" DisplayMemberPath="Description" SelectedValueMemberPath="CorrelationGroupCode" Width="120" UniqueName="CorrelationGroup" >
</telerik:GridViewComboBoxColumn>
<telerik:GridViewDataColumn x:Name="FromValue" UniqueName="From Value" DataMemberBinding="{Binding FromValue}" />
<telerik:GridViewDataColumn x:Name="ToValue" UniqueName="To Value" DataMemberBinding="{Binding ToValue}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
</UserControl>
xaml.cs code:
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 Telerik.Windows.Controls;
using Telerik.Windows;
using PortalMiddleOffice.Web;
using System.ServiceModel.DomainServices.Client;
using System.ComponentModel;
using Telerik.Windows.Controls.GridView;
namespace TestProject
{
public partial class MainPage : UserControl
{
private CorrelationDomainContext _context = new CorrelationDomainContext();
public MainPage()
{
InitializeComponent();
_context = new CorrelacaoDomainContext();
//LoadOperation<CorrelationGroup> loadCorrelationGroup = _context.Load(_context.GetCorrelationGroupsQuery());
//((GridViewComboBoxColumn)this.radGridView1.Columns["CorrelationGroup"]).ItemsSource = loadCorrelationGroup.Entities;
LoadOperation<Legacy> loadLegacies = _context.Load(_context.GetLegaciesQuery());
((GridViewComboBoxColumn)this.radGridView1.Columns["Legacy"]).ItemsSource = loadLegacies.Entities;
this.radGridView1.ItemsSource = _context.vwFromToCorrelation;
_context.Load(_context.GetVwFromToCorrelationsQuery());
this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
}
void comboSelectionChanged(object sender, RadRoutedEventArgs args)
{
RadComboBox comboBox = (RadComboBox)args.OriginalSource;
if (comboBox.SelectedValue == null || comboBox.SelectedValuePath != "LegacyCode") // we take action only if the continent combo is changed
return;
vwFromToCorrelation test = comboBox.DataContext as vwFromToCorrelation;
test.LegacyCode = (int)comboBox.SelectedValue;//we submit the value immediately rather than waiting the cell to lose focus.
}
private void vwFromToCorrelationDomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
}
}
public class vwLocalFromToCorrelation : INotifyPropertyChanged
{
private CorrelationDomainContext _context = new CorrelationDomainContext();
private int? legacyCode;
public int? LegacyCode
{
get
{
return this.legacyCode;
}
set
{
this.legacyCode= value;
this.OnPropertyChanged("LegacyCode");
this.LegacyCode = null;
}
}
private int? correlationGroupCode;
public int? CorrelationGroupCode
{
get
{
return this.correlationGroupCode;
}
set
{
this.correlationGroupCode= value;
this.OnPropertyChanged("CorrelationGroupCode");
}
}
public IEnumerable<CorrelationGroup> AvailableCorrelationGroups
{
get
{
return from c in _context.CorrelationGroups
where c.LegacyCode== this.LegacyCode
select c;
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
After finish binding the RadGridView, all column's are correctly filled, except CorrelationGroup. It stays 'blank'.
I am not so good on silverlight application so maybe the solution is easier than i think.
Thank you very much.
I am having some doubts about how to bind some data to a RadGridView with two cascading combobox column's from a Domain Data Source.
This is my xaml mainpage code:
<UserControl x:Class="TesteProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:my="clr-namespace:TesteProject.Web"
xmlns:my2="clr-namespace:TesteProject">
<Grid x:Name="LayoutRoot">
<telerik:RadGridView Name="radGridView1" AutoGenerateColumns="False" EditTriggers="CellClick">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="CorrelationCode" UniqueName="CorrelationCode" DataMemberBinding="{Binding CorrelationCode}" />
<telerik:GridViewComboBoxColumn x:Name="Legacy" Header="Legacy" HeaderTextAlignment="Center"
DataMemberBinding="{Binding LegacyCode, Mode=TwoWay}" DisplayMemberPath="LegacyDescription" SelectedValueMemberPath="LegacyCode" Width="120" UniqueName="Legacy" >
</telerik:GridViewComboBoxColumn>
<telerik:GridViewComboBoxColumn x:Name="CorrelationGroup" Header="Correlation Group Code" HeaderTextAlignment="Center" ItemsSource="{StaticResource AvailableCorrelationGroups}"
DataMemberBinding="{Binding CorrelationGroupCode, Mode=TwoWay}" DisplayMemberPath="Description" SelectedValueMemberPath="CorrelationGroupCode" Width="120" UniqueName="CorrelationGroup" >
</telerik:GridViewComboBoxColumn>
<telerik:GridViewDataColumn x:Name="FromValue" UniqueName="From Value" DataMemberBinding="{Binding FromValue}" />
<telerik:GridViewDataColumn x:Name="ToValue" UniqueName="To Value" DataMemberBinding="{Binding ToValue}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
</UserControl>
xaml.cs code:
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 Telerik.Windows.Controls;
using Telerik.Windows;
using PortalMiddleOffice.Web;
using System.ServiceModel.DomainServices.Client;
using System.ComponentModel;
using Telerik.Windows.Controls.GridView;
namespace TestProject
{
public partial class MainPage : UserControl
{
private CorrelationDomainContext _context = new CorrelationDomainContext();
public MainPage()
{
InitializeComponent();
_context = new CorrelacaoDomainContext();
//LoadOperation<CorrelationGroup> loadCorrelationGroup = _context.Load(_context.GetCorrelationGroupsQuery());
//((GridViewComboBoxColumn)this.radGridView1.Columns["CorrelationGroup"]).ItemsSource = loadCorrelationGroup.Entities;
LoadOperation<Legacy> loadLegacies = _context.Load(_context.GetLegaciesQuery());
((GridViewComboBoxColumn)this.radGridView1.Columns["Legacy"]).ItemsSource = loadLegacies.Entities;
this.radGridView1.ItemsSource = _context.vwFromToCorrelation;
_context.Load(_context.GetVwFromToCorrelationsQuery());
this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
}
void comboSelectionChanged(object sender, RadRoutedEventArgs args)
{
RadComboBox comboBox = (RadComboBox)args.OriginalSource;
if (comboBox.SelectedValue == null || comboBox.SelectedValuePath != "LegacyCode") // we take action only if the continent combo is changed
return;
vwFromToCorrelation test = comboBox.DataContext as vwFromToCorrelation;
test.LegacyCode = (int)comboBox.SelectedValue;//we submit the value immediately rather than waiting the cell to lose focus.
}
private void vwFromToCorrelationDomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
}
}
public class vwLocalFromToCorrelation : INotifyPropertyChanged
{
private CorrelationDomainContext _context = new CorrelationDomainContext();
private int? legacyCode;
public int? LegacyCode
{
get
{
return this.legacyCode;
}
set
{
this.legacyCode= value;
this.OnPropertyChanged("LegacyCode");
this.LegacyCode = null;
}
}
private int? correlationGroupCode;
public int? CorrelationGroupCode
{
get
{
return this.correlationGroupCode;
}
set
{
this.correlationGroupCode= value;
this.OnPropertyChanged("CorrelationGroupCode");
}
}
public IEnumerable<CorrelationGroup> AvailableCorrelationGroups
{
get
{
return from c in _context.CorrelationGroups
where c.LegacyCode== this.LegacyCode
select c;
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
After finish binding the RadGridView, all column's are correctly filled, except CorrelationGroup. It stays 'blank'.
I am not so good on silverlight application so maybe the solution is easier than i think.
Thank you very much.