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

Strange behaviour of ComboBoxColumn after changing the column

2 Answers 86 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.
Lukas
Top achievements
Rank 1
Lukas asked on 10 Jul 2012, 08:05 AM
Hi. When the RadGridView initializes, everything seems alright. The columns records are shown properly.

As soon as I click somewhere on a column and switch it again all the content of the previous column hides. As soon as I click on it again, the content appears, again. Here my code + screenshots:

C#:
using System;
using System.Collections.ObjectModel;
 
namespace RadGridViewTest2
{
    public partial class MainPage
    {
        public ObservableCollection<MyListEntry> MyListEntries { get; set; }
        public ObservableCollection<OtherEntry> OtherEntries { get; set; }
        public ObservableCollection<Record> Records { get; set; }
        public Record SelectedRecord { get; set; }
 
        public MainPage()
        {
            InitializeComponent();
            MyListEntries = new ObservableCollection<MyListEntry>();
            OtherEntries = new ObservableCollection<OtherEntry>();
            Records = new ObservableCollection<Record>();
 
            for (int i = 0; i < 15; i++)
            {
                MyListEntries.Add(new MyListEntry
                    {
                        Id = Guid.NewGuid(),
                        Name = "MyListEntry" + i
                    });
                OtherEntries.Add(new OtherEntry
                    {
                        Id = Guid.NewGuid(),
                        Name = "OtherEntry" + i,
                        Description = "NewDescription" + i
                    });
            }
 
            var r = new Random();
            for (int i = 0; i < 100; i++)
            {
                Records.Add(new Record
                    {
                        Name = "Record" + i,
                        MyListEntry = MyListEntries[r.Next(14)],
                        OtherEntry = OtherEntries[r.Next(14)]
                    });
            }
            DataContext = this;
        }
    }
 
    public class MyListEntry
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
    }
 
    public class OtherEntry
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
 
    public class Record
    {
        public string Name { get; set; }
        public MyListEntry MyListEntry { get; set; }
        public OtherEntry OtherEntry { get; set; }
    }
}

XAML:
<UserControl x:Class="RadGridViewTest2.MainPage"
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <telerik:RadGridView ItemsSource="{Binding Records}" SelectedItem="{Binding SelectedRecord}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" />
                <telerik:GridViewComboBoxColumn ItemsSource="{Binding MyListEntries, Mode=OneTime}" DisplayMemberPath="Name"
                                                DataMemberBinding="{Binding MyListEntry, Mode=TwoWay}" Header="MyListEntry"/>
                <telerik:GridViewComboBoxColumn ItemsSource="{Binding OtherEntries, Mode=OneTime}"
                                                DataMemberBinding="{Binding OtherEntry, Mode=TwoWay}" Header="OtherEntry" DisplayMemberPath="Name" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>

Help would be greatly appreciated

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 Jul 2012, 09:58 AM
Hello,

 Thank you for the code snippets. 

I would suggest you to check this help article for further instructions on how to resolve the problem. 

All the best,
Didie
the Telerik team

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

0
Lukas
Top achievements
Rank 1
answered on 10 Jul 2012, 10:23 AM
Sorry, I resolved my problem already with help of this link. But as I also mentioned in this post, I write it again in here:

You provided this help article. One suggestion was "1. Expose the ViewModel as a static resource on the page so that it can be easily accessible by the binding". We've been using this for quite some time - but if I remember right, you need to make these lists static, as well, which makes everything quite unhandy. I think since SL5 the approach via RelativeSource is way more elegant. Like this:

<telerik:GridViewComboBoxColumn Header="Category"
            DataMemberBinding="{Binding CategoryID}"
            ItemsSource="{Binding DataContext.Categories, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
            DisplayMemberPath="CategoryName"
            SelectedValueMemberPath="CategoryID" />

This requires that the UsersControls DataContext is properly set. 
Tags
GridView
Asked by
Lukas
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Lukas
Top achievements
Rank 1
Share this question
or