GridViewComboBoxColumn DataMemberBinding

12 posts, 0 answers
  1. Alejandro
    Alejandro avatar
    1 posts
    Member since:
    Aug 2010

    Posted 21 Sep 2010 Link to this post

    Hey!

    So. I'm having a RadGridView which looks something like this (simplified)

    <Grid DataContext="{Binding}" Margin="5,5,5,5" MaxHeight="300" MinHeight="100">                                
                                    <telerik:RadGridView x:Name="DeliverableTypesGridView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"                                                                         
                                        ShowGroupPanel="False"
                                        SelectionMode="Single"
                                        AutoGenerateColumns="False"                                    
                                        CanUserReorderColumns="False"
                                        CanUserDeleteRows="False"
                                        CanUserInsertRows="True"                                    
                                        ShowInsertRow="True"
                                        ItemsSource="{Binding DeliverableTypes}">                                    
                                        <telerik:RadGridView.Columns>
                                            <telerik:GridViewSelectColumn />
                                            <telerik:GridViewDataColumn Header="Code" DataMemberBinding="{Binding Code, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"  />
                                            <telerik:GridViewDataColumn Header="DeliverableType" DataMemberBinding="{Binding Description}" IsReadOnly="True" />                                        
                                                                           
                                            <telerik:GridViewComboBoxColumn Header="Due Date Rule"
                                                                            DataMemberBinding="{Binding DueDateRule.Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                                            ItemsSource="{Binding ReferenceData.AllDueDateRules}"                                                                         
                                                                            DisplayMemberPath="Description"                                                                        
                                                                            />                                                                               
                                            <telerik:GridViewCheckBoxColumn Header="Active"  DataMemberBinding="{Binding Active}" />
                                            <telerik:GridViewDataColumn Header="Comments" DataMemberBinding="{Binding Comments}"/>
                                            <telerik:GridViewDataColumn Header="Created By" DataMemberBinding="{Binding CreatedBy}" IsReadOnly="True" />
                                            <telerik:GridViewDataColumn Header="Created On" DataFormatString="{}{0:M/d/yyyy}" IsVisible="True" DataMemberBinding="{Binding CreatedOn}" IsReadOnly="True"/>
                                            <telerik:GridViewDataColumn Header="Last Modified By" DataMemberBinding="{Binding LastModifiedBy}" IsReadOnly="True"/>
                                            <telerik:GridViewDataColumn Header="Last Modified On" DataFormatString="{}{0:M/d/yyyy}" IsVisible="True" DataMemberBinding="{Binding LastModifiedOn}" IsReadOnly="True"/>                                        
                                        </telerik:RadGridView.Columns>
                                    </telerik:RadGridView>
                                </Grid>

    Concentrate on the GridViewComboBoxColumn. I'm successfully binding my item source to the combo box on every row has.
    But the thing is that when the Grid appears on the screen the GridViewComboBoxColumn  column shows no information.

    As I'm using WPF MVVM pattern I'm having a public ObservableCollection<DeliverableTypeModel> DeliverableTypes property on a ManageDeliverableViewModel.cs whcih I use as DataConext. My DeliverableTypeModel.cs has a DeliverableDueDateRule Property as well.

    My intention is to show the value that the DeliverableDueDateRule Property  has under this field in the grid ,
    but I get a blank column instead.
    The thing that is working is that when I click on a cell of the blank column I get a comboBox whith the items on the items source

    Thanks!
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 22 Sep 2010 Link to this post

    Hi Alejandro,

    In order to provide you with an appropriate solution, I would need a bit more information about your project and more specifically about the ItemsSource of the GridViewComboBoxColumn. Basically, the Property set for the DataMemberBinding needs to correspond to a property in the ItemsSource of the grid. This is the way the two elements - the column and the grid - communicate and know which item should appear in the ComboBoxColumn.
    I am sending you a sample project illustrating the implementation of the GridViewComboBoxColumn.

    Regards,
    Maya
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Srikanth
    Srikanth avatar
    8 posts
    Member since:
    Sep 2010

    Posted 15 Jan 2012 Link to this post

    Hi, I followed the sample code you sent and it is very odd that if I set my view model to be data context of the root layout and then set the ItemsSource for the RadGridView and GridViewComboxColumn in XAML, the GridView displays fine but the combo box column is empty and if I set the ItemsSource explicitely in the code behind as done in your sample code (zip file) it works as expected. I am using the Rad Control for Silverlight 4. Can you send me a variation of the sample code with ItemsSource set in the XAML for the Grid and ComboBoxColumn.? OR can you see what I am doing wrong?
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 16 Jan 2012 Link to this post

    Hello,

    You can define the Source property of the Binding explicitly pointing to your ViewModel. For example:
    <telerik:GridViewComboBoxColumn Header="Category"
                DataMemberBinding="{Binding CategoryID}"
                ItemsSource="{Binding Path=Categories, Source={StaticResource mainPageViewModel}}"
                DisplayMemberPath="CategoryName"
                SelectedValueMemberPath="CategoryID" />

    In the project above you can follow the same idea (however, you will need to define Countries property in your ViewModel).
    You can take a look at this article for a reference as well.

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Srikanth
    Srikanth avatar
    8 posts
    Member since:
    Sep 2010

    Posted 17 Jan 2012 Link to this post

    Thanks Maya, I managed to get it working with a CollectionViewSource. This was something blocking me from doing a scenario where i have to change the text of one of the grod voew columsn based on the selection made in the gridviewcomboboxcolumn. In the sample code below I have to get the rank column change whenever I change the employee in the combo box. I was looking for something like a SelectedValue property of RadComboBox, a object which I can directly bind to Employee type, and then use its properties to bind. Any help is appreciated. Thanks.
    public class Campaign
    {
        public Employee Employee { get; set:}
    }
    public class Employee
    {
        public  string Id { get; set:}
        public  string Name { get; set:}
        public  string Rank { get; set:}
    }
     
    ViewModel has:
    ObservableColelction<Employee> Employees;
    ObservableColelction<Campaigns> Campaigns;
     
    XAML:
    <UserControl.Resources>
            <CollectionViewSource x:Key="EmployeeViewSource" Source="{Binding Employees}"/>
        </UserControl.Resources>
     
    <Controls:RadGridView x:Name="CampignGridView" ItemsSource="{Binding Path=Campaigns}">
    <Controls:RadGridView.Columns>
            <telerik:GridViewComboBoxColumn Header="Employee" DataMemberBinding="{Binding Employee.Id, Mode=TwoWay}"
                                                    ItemsSource="{Binding Source={StaticResource EmployeeViewSource}}"
                                                    SelectedValueMemberPath="Id"
                                                    DisplayMemberPath="Name"/>
             <telerik:GridViewDataColumn Header="Rank" ?????? " />
    </Controls:RadGridView.Columns>       
    </Controls:RadGridView
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Jan 2012 Link to this post

    Hello,

    There are a couple of possible approaches here. For example:
    1. You can define RadComboBox in a CellEditTemplate for the combo box column and work with its SelectedValue, SelectedItem, etc. properties.
    2. You can add handler for SelectionChanged event of RadComboBox (just as illustrated in this forum thread) and update the value of the 'Rank' property, once you make any selection. 
    3. You can perform all that logic inside the implementation of your business object - once Id property is updated (when a new value is selected from the combo box column), you can update the value of the 'Rank' property as well. 
    Let me know if you have any difficulties implementing the one that is most appropriate for you.

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. srikanth
    srikanth avatar
    23 posts
    Member since:
    Jul 2012

    Posted 22 Jun 2013 Link to this post

    Hello Maya!

    How can i add event handler for selection changed through MVVM way???
    Could you give me some sample or snippet how to do this?

    Thanks in Advance!
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Jun 2013 Link to this post

    Hello Srikanth,

    You cannot add handler in the ViewModel as it is in the second suggested approach. If you follow the first approach and work directly with RadComboBox, you can create an attached behavior for it and keep your code behind clean.  

    Regards,
    Maya
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Vijaya
    Vijaya avatar
    1 posts
    Member since:
    Dec 2013

    Posted 12 Dec 2013 Link to this post

    GridViewComboBoxColumn is read only property is not disabling the combo box 

  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 16 Dec 2013 Link to this post

    Hi Vijaya,

    I have tested the scenario, but I was not able to reproduce it. I am attaching the sample I used for the test. Will it be possible to take a look at it and let me know if I am missing anything ?

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  12. Alexander
    Alexander avatar
    21 posts
    Member since:
    Aug 2014

    Posted 11 Jul Link to this post

    Hi,

    my scenario is nearly the same. The problem is that the ComboBox column shows the same text (of the first row) in every Row and when I select another dye the ComboBoxColumn doesn't actualize the text.

    My Datamodel consists of three tables. The Recipe table, Dye table and the RecipeDye table which describes which Dyes belong to a Recipe.

    I have a GridView which lists the Dyes that belong to the selected Recipe. The user can edit the rows of the GridView to edit the dyes of the recipe. For that I want a ComboBoxCell which lists the available dyes and displays the name of the selected dye.

    I hope my description was understandable, here is the XAML Code and the code of the three ViewModels:

    <telerik:RadGridView x:Name="gvRecipeDye" Grid.Row="1" Grid.RowSpan="4" Grid.Column="6" ShowGroupPanel="False" CanUserFreezeColumns="False" IsFilteringAllowed="False"
                                             SelectionMode="Single" RowIndicatorVisibility="Collapsed" CanUserInsertRows="True"
                                             DataContext="{StaticResource RecipeDyeViewModel}" ItemsSource="{Binding RecipeDye}"
                                             Width="300" AutoGenerateColumns="False" NewRowPosition="Bottom" GroupRenderMode="Flat">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Name="cColor" Header="Farbe" IsReadOnly="True" CellStyle="{StaticResource GridViewCellStyleColor}"/>
            <telerik:GridViewComboBoxColumn Width="2*" Name="cDyeDescription" Header="Bezeichnung"
                                            DataContext="{StaticResource DyeViewModel}" ItemsSource="{Binding Dye}"
                                            DataMemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadGridView}},Path=DataContext.Id_Dye}"
                                            DisplayMemberPath="Name"
                                            SelectedValueMemberPath="Id_Dye"/>
            <telerik:GridViewMaskedInputColumn MaskType="Numeric" Width="1*" Name="cDyeQuantity" Header="Menge (g)" DataMemberBinding="{Binding DyeQuantity}"/>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Windows;
    using System.Windows.Media;
    using Telerik.Windows.Controls;
    using WpfCodebase;
     
    namespace DyeingControl
    {
        public class Recipe : INotifyPropertyChanged
        {
            public int Id
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public Visibility NewRecipe
            {
                get { return GetPropertyValue<Visibility>(); }
                set { SetPropertyValue(value); }
            }
     
            public bool Saved
            {
                get { return GetPropertyValue<bool>(); }
                set { SetPropertyValue(value); }
            }
     
            public int Id_MachineType
            {
                get { return GetPropertyValue<int>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public int Id_RecipeStatus
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public int Id_DyeType
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public SolidColorBrush Color
            {
                get { return GetPropertyValue<SolidColorBrush>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string Name
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public string Fleet
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public MachineType SelectedMachineType
            {
                get { return GetPropertyValue<MachineType>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string RecipeStatus
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public RecipeStatus SelectedRecipeStatus
            {
                get { return GetPropertyValue<RecipeStatus>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string DyeTypeTitle
            {
                get { return GetPropertyValue<string>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public DyeType SelectedDyeType
            {
                get { return GetPropertyValue<DyeType>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string Creator
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public string Created
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public string LastEditedBy
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public string LastEdited
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            #region Constructors
            public Recipe()
            {
                this.Name = string.Empty;
                this.Creator = string.Empty;
                this.Created = null;
                this.LastEditedBy = string.Empty;
                this.LastEdited = null;
                this.Fleet = string.Empty;
                this.RecipeStatus = string.Empty;
                this.DyeTypeTitle = string.Empty;
     
                this.NewRecipe = Visibility.Visible;
                this.Saved = false;
            }
     
            public Recipe(int id, string color, string name, int id_MachineType, string fleet, int id_RecipeStatus, string status, int id_DyeType, string dyeTypeTitle,
                          string creator, string created, string lastEditedBy, string lastEdited)
            {
                this.Id = id;
                this.Name = name;
                this.Creator = creator;
                this.Created = created;
                this.LastEditedBy = lastEditedBy;
                this.LastEdited = lastEdited;
                this.Fleet = fleet;
                this.RecipeStatus = status;
                this.DyeTypeTitle = dyeTypeTitle;
     
                this.SelectedMachineType = MachineTypeViewModel.MachineTypes.Where(x => x.Id == id_MachineType).First();
                this.SelectedRecipeStatus = RecipeStatusViewModel.RecipeStatuses.Where(x => x.Id == id_RecipeStatus).First();
                this.SelectedDyeType = DyeTypeViewModel.DyeTypes.Where(x => x.Id == id_DyeType).First();
     
                System.Drawing.Color clrTemp = ColorTranslator.FromHtml(color);
                this.Color = new SolidColorBrush(System.Windows.Media.Color.FromArgb(clrTemp.A, clrTemp.R, clrTemp.G, clrTemp.B));
     
                this.NewRecipe = Visibility.Collapsed;
                this.Saved = true;
            }
            #endregion
     
            #region DO NOT CHANGE!
     
            private ILookup<string, string> _dependentLookup;
            private ILookup<string, string> DependentLookup
            {
                get
                {
                    return _dependentLookup ?? (_dependentLookup = (from p in GetType().GetProperties()
                                                                    let attrs = p.GetCustomAttributes(typeof(NotifiesOnAttribute), false)
                                                                    from NotifiesOnAttribute a in attrs
                                                                    select new { Independent = a.Name, Dependent = p.Name }).ToLookup(i => i.Independent, d => d.Dependent));
                }
            }
      
            protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                var propertyChanged = PropertyChanged;
                if (propertyChanged != null)
                {
                    propertyChanged(this, new PropertyChangedEventArgs(propertyName));
      
                    foreach (var dependentPropertyName in DependentLookup[propertyName])
                    {
                        RaisePropertyChanged(dependentPropertyName);
                    }
                }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            private readonly Dictionary<string, object> _propertyBackingDictionary = new Dictionary<string, object>();
            protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
            {
                PropertyChangedEventHandler handler = this.PropertyChanged;
                if (handler != null)
                {
                    handler(this, args);
                }
            }
     
            private void OnPropertyChanged([CallerMemberName] string propertyName = null)
            {
                this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
            }
       
            protected T GetPropertyValue<T>([CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                object value;
                if (_propertyBackingDictionary.TryGetValue(propertyName, out value))
                {
                    return (T)value;
                }
      
                return default(T);
            }
      
            protected bool SetPropertyValue<T>(T newValue, [CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                if (EqualityComparer<T>.Default.Equals(newValue, GetPropertyValue<T>(propertyName))) return false;
      
                _propertyBackingDictionary[propertyName] = newValue;
                OnPropertyChanged(propertyName);
                return true;
            }
     
            #endregion
        }
     
        public class RecipeViewModel : ViewModelBase
        {
            private ObservableCollection<Recipe> recipe;
            public ObservableCollection<Recipe> Recipe
            {
                get
                {
                    if (this.recipe == null)
                    {
                        this.recipe = this.CreateRecipes();
                    }
     
                    return this.recipe;
                }
            }
     
            private ObservableCollection<Recipe> CreateRecipes()
            {
                ObservableCollection<Recipe> recipes = new ObservableCollection<Recipe>();
                Recipe recipe;
     
                foreach (DataRow recipeRow in RecipeManagement.dtRecipes.Rows)
                {
                    recipe = new Recipe(Convert.ToInt32(recipeRow["Id"]), recipeRow["Color"].ToString(), recipeRow["Name"].ToString(),
                                        Convert.ToInt32(recipeRow["Id_MachineType"]), recipeRow["Fleet"].ToString(),
                                        Convert.ToInt32(recipeRow["Id_RecipeStatus"]), recipeRow["Status"].ToString(),
                                        Convert.ToInt32(recipeRow["Id_DyeType"]), recipeRow["DyeTypeTitle"].ToString(),
                                        recipeRow["Creator"].ToString(), recipeRow["Created"].ToString(), recipeRow["LastEditedBy"] != DBNull.Value ? recipeRow["LastEditedBy"].ToString() : string.Empty,
                                        recipeRow["LastEdited"] != DBNull.Value ? recipeRow["LastEdited"].ToString() : string.Empty);
                    recipes.Add(recipe);
                }
     
                return recipes;
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Windows;
    using System.Windows.Media;
    using Telerik.Windows.Controls;
    using WpfCodebase;
     
    namespace DyeingControl
    {
        public class Dye : INotifyPropertyChanged
        {
            public int Id
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public Visibility NewDye
            {
                get { return GetPropertyValue<Visibility>(); }
                set { SetPropertyValue(value); }
            }
     
            public bool Saved
            {
                get { return GetPropertyValue<bool>(); }
                set { SetPropertyValue(value); }
            }
     
            public SolidColorBrush DyeColor
            {
                get { return GetPropertyValue<SolidColorBrush>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string Name
            {
                get { return GetPropertyValue<string>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string Manufacturer
            {
                get { return GetPropertyValue<string>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public string Description
            {
                get { return GetPropertyValue<string>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public DyeType SelectedDyeType
            {
                get { return GetPropertyValue<DyeType>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            public int Id_Type
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public string TypeTitle
            {
                get { return GetPropertyValue<string>(); }
                set
                {
                    SetPropertyValue(value);
                }
            }
     
            #region Constructors
            public Dye()
            {
                this.Name = string.Empty;
                this.Manufacturer = string.Empty;
                this.Description = string.Empty;
                this.TypeTitle = string.Empty;
     
                this.NewDye = Visibility.Visible;
                this.Saved = false;
            }
     
            public Dye(int id, string color, string name, string description, string manufacturer, string descriptionType, int id_DyeType)
            {
                this.Id = id;
                this.Id_Type = id_DyeType;
                this.Name = name;
                this.Manufacturer = manufacturer;
                this.Description = description;
                this.TypeTitle = descriptionType;
     
                System.Drawing.Color clrTemp = ColorTranslator.FromHtml(color);
                this.DyeColor = new SolidColorBrush(System.Windows.Media.Color.FromArgb(clrTemp.A, clrTemp.R, clrTemp.G, clrTemp.B));
     
                this.SelectedDyeType = DyeTypeViewModel.DyeTypes.Where(x => x.Id == id_DyeType).First();
     
                this.NewDye = Visibility.Collapsed;
                this.Saved = true;
            }
            #endregion
     
            #region DO NOT CHANGE!
     
            private ILookup<string, string> _dependentLookup;
            private ILookup<string, string> DependentLookup
            {
                get
                {
                    return _dependentLookup ?? (_dependentLookup = (from p in GetType().GetProperties()
                                                                    let attrs = p.GetCustomAttributes(typeof(NotifiesOnAttribute), false)
                                                                    from NotifiesOnAttribute a in attrs
                                                                    select new { Independent = a.Name, Dependent = p.Name }).ToLookup(i => i.Independent, d => d.Dependent));
                }
            }
      
            protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                var propertyChanged = PropertyChanged;
                if (propertyChanged != null)
                {
                    propertyChanged(this, new PropertyChangedEventArgs(propertyName));
      
                    foreach (var dependentPropertyName in DependentLookup[propertyName])
                    {
                        RaisePropertyChanged(dependentPropertyName);
                    }
                }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            private readonly Dictionary<string, object> _propertyBackingDictionary = new Dictionary<string, object>();
            protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
            {
                PropertyChangedEventHandler handler = this.PropertyChanged;
                if (handler != null)
                {
                    handler(this, args);
                }
            }
     
            private void OnPropertyChanged([CallerMemberName] string propertyName = null)
            {
                this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
            }
       
            protected T GetPropertyValue<T>([CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                object value;
                if (_propertyBackingDictionary.TryGetValue(propertyName, out value))
                {
                    return (T)value;
                }
      
                return default(T);
            }
      
            protected bool SetPropertyValue<T>(T newValue, [CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                if (EqualityComparer<T>.Default.Equals(newValue, GetPropertyValue<T>(propertyName))) return false;
      
                _propertyBackingDictionary[propertyName] = newValue;
                OnPropertyChanged(propertyName);
                return true;
            }
     
            #endregion
        }
     
        public class DyeViewModel : ViewModelBase
        {
            private static ObservableCollection<Dye> dye;
            public static ObservableCollection<Dye> Dye
            {
                get
                {
                    if (DyeViewModel.dye == null)
                    {
                        DyeViewModel.dye = DyeViewModel.CreateDyes();
                    }
     
                    return DyeViewModel.dye;
                }
            }
     
            private static ObservableCollection<Dye> CreateDyes()
            {
                ObservableCollection<Dye> dyes = new ObservableCollection<Dye>();
                Dye dye;
     
                foreach (DataRow dyeRow in RecipeManagement.dtDye.Rows)
                {
                    dye = new Dye(Convert.ToInt32(dyeRow["Id"]), dyeRow["color"].ToString(), dyeRow["Name"].ToString(), dyeRow["Description"].ToString(), dyeRow["Manufacturer"].ToString(),
                                  dyeRow["Type"].ToString(), Convert.ToInt32(dyeRow["Id_DyeType"]));
                    dyes.Add(dye);
                }
     
                return dyes;
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Windows.Media;
    using Telerik.Windows.Controls;
    using WpfCodebase;
     
    namespace DyeingControl
    {
        public class RecipeDye : INotifyPropertyChanged
        {
            public int Id
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public int Id_Recipe
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public int Id_Dye
            {
                get { return GetPropertyValue<int>(); }
                set { SetPropertyValue(value); }
            }
     
            public string DyeName
            {
                get { return GetPropertyValue<string>(); }
                set { SetPropertyValue(value); }
            }
     
            public decimal DyeQuantity
            {
                get { return GetPropertyValue<decimal>(); }
                set { SetPropertyValue(value); }
            }
     
            public SolidColorBrush Color
            {
                get { return GetPropertyValue<SolidColorBrush>(); }
                set { SetPropertyValue(value); }
            }
     
            public RecipeDye(int id, int id_recipe, int id_dye, decimal dyequantity)
            {
                this.Id = id;
                this.Id_Recipe = id_recipe;
                this.Id_Dye = id_dye;
     
                this.DyeName = (DyeViewModel.Dye.Where(x => x.Id == id_dye).First()).Name;
                this.DyeQuantity = dyequantity;
     
                this.Color = (DyeViewModel.Dye.Where(x => x.Id == id_dye).First()).DyeColor;
            }
     
            public RecipeDye(int id, int id_recipe, int id_dye, string dyename, decimal dyequantity, string color)
            {
                this.Id = id;
                this.Id_Recipe = id_recipe;
                this.Id_Dye = id_dye;
                this.DyeName = dyename;
                this.DyeQuantity = dyequantity;
     
                System.Drawing.Color clrTemp = ColorTranslator.FromHtml(color);
                this.Color = new SolidColorBrush(System.Windows.Media.Color.FromArgb(clrTemp.A, clrTemp.R, clrTemp.G, clrTemp.B));
            }
     
            #region Fixed Methods
     
            private ILookup<string, string> _dependentLookup;
            private ILookup<string, string> DependentLookup
            {
                get
                {
                    return _dependentLookup ?? (_dependentLookup = (from p in GetType().GetProperties()
                                                                    let attrs = p.GetCustomAttributes(typeof(NotifiesOnAttribute), false)
                                                                    from NotifiesOnAttribute a in attrs
                                                                    select new { Independent = a.Name, Dependent = p.Name }).ToLookup(i => i.Independent, d => d.Dependent));
                }
            }
      
            protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                var propertyChanged = PropertyChanged;
                if (propertyChanged != null)
                {
                    propertyChanged(this, new PropertyChangedEventArgs(propertyName));
      
                    foreach (var dependentPropertyName in DependentLookup[propertyName])
                    {
                        RaisePropertyChanged(dependentPropertyName);
                    }
                }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            private readonly Dictionary<string, object> _propertyBackingDictionary = new Dictionary<string, object>();
            protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
            {
                PropertyChangedEventHandler handler = this.PropertyChanged;
                if (handler != null)
                {
                    handler(this, args);
                }
            }
     
            private void OnPropertyChanged([CallerMemberName] string propertyName = null)
            {
                this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
            }
       
            protected T GetPropertyValue<T>([CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                object value;
                if (_propertyBackingDictionary.TryGetValue(propertyName, out value))
                {
                    return (T)value;
                }
      
                return default(T);
            }
      
            protected bool SetPropertyValue<T>(T newValue, [CallerMemberName] string propertyName = null)
            {
                if (propertyName == null) throw new ArgumentNullException("propertyName");
      
                if (EqualityComparer<T>.Default.Equals(newValue, GetPropertyValue<T>(propertyName))) return false;
      
                _propertyBackingDictionary[propertyName] = newValue;
                OnPropertyChanged(propertyName);
                return true;
            }
     
            #endregion
        }
     
        public class RecipeDyeViewModel : ViewModelBase
        {
            private static ObservableCollection<RecipeDye> recipedye;
            public static ObservableCollection<RecipeDye> RecipeDye
            {
                get
                {
                    if (RecipeDyeViewModel.recipedye == null)
                    {
                        RecipeDyeViewModel.recipedye = RecipeDyeViewModel.CreateRecipeDye();
                    }
     
                    return RecipeDyeViewModel.recipedye;
                }
            }
     
            private static ObservableCollection<RecipeDye> CreateRecipeDye()
            {
                ObservableCollection<RecipeDye> recipedyes = new ObservableCollection<RecipeDye>();
                RecipeDye recipedye;
     
                foreach (DataRow recipeDyeRow in RecipeManagement.dtRecipeDye.Rows)
                {
                    recipedye = new RecipeDye(Convert.ToInt32(recipeDyeRow["Id"]), Convert.ToInt32(recipeDyeRow["Id_Recipe"]), Convert.ToInt32(recipeDyeRow["Id_Dye"]),
                                              recipeDyeRow["Name"].ToString(), Convert.ToDecimal(recipeDyeRow["DyeQuantity"]), recipeDyeRow["Color"].ToString());
                    recipedyes.Add(recipedye);
                }
     
                return recipedyes;
            }
        }
    }
  13. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    281 posts

    Posted 13 Jul Link to this post

    Hi Alexander,

    Would it be possible to raise a ticket and provide us with a sample project that shows the setup at your end as it would be much easier for us to investigate the issue and advise you accordingly? Apart from that,  my advice is to check the demos regarding the GridViewComboBoxColumn in our SDK Samples Browser and the article in our online documentation and make sure that you are following the instructions. 

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready