Binding GridViewComboBoxColumn to a RadObservableCollection ?

11 posts, 0 answers
  1. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 04 Jun 2010 Link to this post

    I try to bind the ItemsSourceBinding of this RadComboboxColumn to a RadObservableCollection filed with a addrange from the web context of my RIA Service.

     

     

     

     

     

     

     

     

    <telerikGridView:GridViewComboBoxColumn Header="Fréquence" SelectedValueMemberPath="ID" DisplayMemberPath="Type" 
        
    DataMemberBinding="{Binding TypePrixID}" ItemsSourceBinding="{Binding TypePrix, Mode=OneWay}"/> 

     

            public RadObservableCollection<TypePrix> TypePrix  
            {  
                get { return m_TypePrix; }  
                set  
                {  
                    m_TypePrix = value;  
                    RaisePropertyChanged("TypePrix");  
                }  
            } 

    But I got this execption:
    Message: System.InvalidCastException: can't cast object type 'GestionMembre.Web.ORM.TypePrix' in 'System.Collections.IEnumerable'.

  2. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 08 Jun 2010 Link to this post

    Can someone point me in? I need to make this grid working.

    Thanks
  3. DevCraft banner
  4. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 08 Jun 2010 Link to this post

    Ok now with the new version of telerik control (SP2) I do not have exception anymore, but the combobox are always empty.
  5. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 08 Jun 2010 Link to this post

    ok I change my code for
                                    <telerikGridView:GridViewComboBoxColumn Header="Type" MinWidth="120" SelectedValueMemberPath="ID" DisplayMemberPath="Nom" 
                                               DataMemberBinding="{Binding TypeAdhesion}" ItemsSource="{Binding TypesAdhesion, Mode=OneWay}">  
                                    </telerikGridView:GridViewComboBoxColumn> 
     and that work, but I need to click one time on the column to display the selected vallue. If I doubleclick the combobox apear and i can select another value.

    Help please...
  6. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 14 Jun 2010 Link to this post

    Hi Pierre,

    Sorry for the late answer. To keep communication consistent and avoid duplication , I have posted the answer in your relevant support ticket.

    All the best,
    Pavel Pavlov
    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.
  7. Kurt Mang
    Kurt Mang avatar
    12 posts
    Member since:
    Mar 2010

    Posted 24 Jun 2010 Link to this post

    Guys - I have a similar problem. I am having difficulty getting my grid to bind to a viewmodel that exposes essentailly a collection of items that expose a single collection each - I want to bind these individual collections to the columns of a grid.

    Example:

    ViewModel: FieldItems = ObservableCollection<FieldItem> [I want this to be my grid's ItemsSource]

    FieldItem: Name = string [I want this to be the column header]
    Results = ObservableCollection<string> [I want these to be the individual row column data items]

    At runtime, I loop through the MainCollection items, create a column for each and create the binding in code (like so):

    public partial class GridControl : UserControl 
      { 
        GridViewModel _viewModel; 
     
        public GridControl(GridViewModel viewModel) 
        { 
          InitializeComponent(); 
          _viewModel = viewModel; 
          _viewModel.DataLoaded += DataLoaded; 
          this.DataContext = _viewModel
        } 
     
        void DataLoaded(object sender, EventArgs e) 
        { 
          _viewModel.DataLoaded -DataLoaded
          BuildDataBindings(); 
        } 
     
        private void BuildDataBindings() 
        { 
          // this is where we'd build grid columns with names etc. 
          GridViewDataColumn column; 
          foreach (var vm in _viewModel.FieldItems) 
          { 
            column = new GridViewDataColumn(); 
            column.Header = vm.Name; 
            column.UniqueName = vm.Name; 
            column.DataType = typeof(System.String); 
            // column.CellTemplate = (DataTemplate)this.Resources["VClassColumnTemplate"]; 
            column.DataMemberBinding = PrepareDataMemberBinding(vm); 
     
            grid.Columns.Add(column); 
          } 
          grid.ItemsSource = _viewModel.FieldItems; 
     
        } 
     
        private System.Windows.Data.Binding PrepareDataMemberBinding(object dataSource) 
        { 
          Binding binding = new Binding(); 
          binding.Path = new PropertyPath("Results"); 
          binding.Source = dataSource
          // binding.BindsDirectlyToSource = true; // ?? 
          return binding; 
        } 
     
      } 


    Doesn't work - the grid actually seems to bind the entire ObservableCollection<string> into each individual cell. I know this is possible - it must be - but I've tried everything I can think of, no luck.

    Thanks for any help!

    Kurt - Vancouver BC
  8. Kurt Mang
    Kurt Mang avatar
    12 posts
    Member since:
    Mar 2010

    Posted 24 Jun 2010 Link to this post

    Just an update: in the BuildDataBindings() method, this doesn't work either:

    column.DataType = typeof(ObservableCollection<string>);
    OR
    column.DataType = typeof(VClassFieldItem)

    Also, BindsDirectlyToSource seems ot have no impact either.
    Kurt
  9. Kurt Mang
    Kurt Mang avatar
    12 posts
    Member since:
    Mar 2010

    Posted 24 Jun 2010 Link to this post

    I solved this problem by using Vlad's DataTable solution: 
    http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx

    Works great in SL4, Q12010 controls. Awesome!

    Kurt
  10. Travis
    Travis avatar
    223 posts
    Member since:
    Jan 2003

    Posted 24 Aug 2010 Link to this post

    So can we see what the solution was?  I too have the problem that Piere was having where the user has to click on the cell in order to see the display value of the combobox.  You said you fixed it for him in a support ticket.
  11. Pierre
    Pierre avatar
    212 posts
    Member since:
    Apr 2007

    Posted 24 Aug 2010 Link to this post

    I solve this "ghost" effect like this:

    private void GridTelephone_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        RadGridView GridTel = e.Row.ParentOfType<RadGridView>();
        ((GridViewComboBoxColumn)GridTel.Columns[0]).ItemsSource = m_ucAdresseVM.TypeTelephone;
    }
  12. Travis
    Travis avatar
    223 posts
    Member since:
    Jan 2003

    Posted 24 Aug 2010 Link to this post

    Thanks Pierre!!  That worked for me :)
Back to Top
DevCraft banner