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

Binding GridViewComboBoxColumn to a RadObservableCollection ?

10 Answers 189 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 2
Iron
Iron
Pierre asked on 04 Jun 2010, 04:16 PM

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'.

10 Answers, 1 is accepted

Sort by
0
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 08 Jun 2010, 01:32 PM
Can someone point me in? I need to make this grid working.

Thanks
0
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 08 Jun 2010, 02:53 PM
Ok now with the new version of telerik control (SP2) I do not have exception anymore, but the combobox are always empty.
0
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 08 Jun 2010, 03:22 PM
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...
0
Pavel Pavlov
Telerik team
answered on 14 Jun 2010, 04:21 PM
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.
0
Kurt Mang
Top achievements
Rank 1
answered on 24 Jun 2010, 05:44 PM
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
0
Kurt Mang
Top achievements
Rank 1
answered on 24 Jun 2010, 06:39 PM
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
0
Kurt Mang
Top achievements
Rank 1
answered on 24 Jun 2010, 11:23 PM
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
0
Travis
Top achievements
Rank 1
answered on 24 Aug 2010, 05:50 PM
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.
0
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 24 Aug 2010, 06:02 PM
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;
}
0
Travis
Top achievements
Rank 1
answered on 24 Aug 2010, 06:16 PM
Thanks Pierre!!  That worked for me :)
Tags
GridView
Asked by
Pierre
Top achievements
Rank 2
Iron
Iron
Answers by
Pierre
Top achievements
Rank 2
Iron
Iron
Pavel Pavlov
Telerik team
Kurt Mang
Top achievements
Rank 1
Travis
Top achievements
Rank 1
Share this question
or