GridViewComboBoxColumn problem

6 posts, 1 answers
  1. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 21 Mar 2013 Link to this post

    I've been stumbling all over this all day and need some direction.  I've paired down my code and am posting it in hopes that someone can tell me what I'm doing wrong.
    The xaml...
    <telerik:RadGridView AutoGenerateColumns="False"
                            ItemsSource="{Binding Screens}">
        <telerik:RadGridView.Columns>
            <telerik:GridViewComboBoxColumn x:Name="ScreenTypeCombo"
                                            UniqueName="ScreenTypeCombo"
                                            Header="Screen Type"
                                            Width="150"
                                            DataMemberBinding="{Binding SelectedScreenType}"
                                            SelectedValueMemberPath="ScreenType"
                                            DisplayMemberPath="Literal"
                                            ItemsSourceBinding="{Binding ScreenTypeLiterals}" />
        </telerik:RadGridView.Columns>


    The ViewModel...

    public enum ScreenTypes
    {
        Master,
        Vertical,
        Multicolumn,
        Wrap,
        Detail,
        Transaction,
        Notes
    }
     
    public class ScreenTypeLiteral
    {
        public ScreenTypes ScreenType
        {
            get;
            set;
        }
     
        public String Literal
        {
            get;
            set;
        }
     
        public ScreenTypeLiteral(ScreenTypes type, String lit)
        {
            ScreenType = type;
            Literal = lit;
        }
    }
     
    public class ScreenDescriptor
    {
        public ICollectionView ScreenTypeLiterals
        {
            get
            {
                return _ScreenTypeLiterals;
            }
            set
            {
                _ScreenTypeLiterals = value;
                OnPropertyChanged(() => ScreenTypeLiterals);
            }
        }
        private ICollectionView _ScreenTypeLiterals;
     
        public ScreenTypeLiteral SelectedScreenType
        {
            get
            {
                return ScreenTypeLiterals.CurrentItem as ScreenTypeLiteral;
            }
        }
     
        public ScreenDescriptor()
        {
            ScreenTypeLiterals = CollectionViewSource.GetDefaultView(new List<ScreenTypeLiteral>()
            {
                {new ScreenTypeLiteral(ScreenTypes.Master, "Master View")},
                {new ScreenTypeLiteral(ScreenTypes.Vertical, "Detail View")},
            });
            ScreenTypeLiterals.MoveCurrentToFirst();
        }
     
    }
     
    public class Descriptor
    {
        public ICollectionView Screens
        {
            get
            {
                return _screens;
            }
            set
            {
                _screens = value;
                OnPropertyChanged(() => Screens);
            }
        }
        private ICollectionView _screens = null;
     
        public Descriptor()
        {
            var list = new List<ScreenDescriptor>();
            list.Add(new ScreenDescriptor());
            list.Add(new ScreenDescriptor());
     
            Screens = CollectionViewSource.GetDefaultView(list);
            Screens.MoveCurrentToFirst();
        }
     
    }


    Thanks in advance,
    Steve
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Mar 2013 Link to this post

    Hello,

    I would suggest you to read through the online documentation on how to configure the GridViewComboBoxColumn properly.

    Please let me know if you have any additional questions. 

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 22 Mar 2013 Link to this post

    I have read the documentation and searched the forums, and as far as I can see, I am doing everything correctly; however no data is displayed, and the ComboBox is not even displayed.  See the attached file and please review the code I posted.  If you need further information, please let me know.
    Thank you,
    Steve
  5. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Mar 2013 Link to this post

    Hello,

    Please note that the source set for the ItemsSourceBinding should be a property of the business object the grid row is bound to. Looking at the provided source code, this is correct. Then the DataMemberBinding is set to SelectedScreenType which is set to ScreenTypeLiterals.CurrentItem. Is there a value set for the ScreenTypeLiterals.CurrentItem?

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 25 Mar 2013 Link to this post

    Hi Didie,
    Your response caused me to look again at how the DataMemberBinding was assigned and I found two things that were a problem.  First, the type of the property should have been ScreenTypeLiteral.ScreenType.  The second, and I'm not sure why was returning the CurrentItem of the collection.  By creating a field behind the SelectedScreenType of ScreenTypeLiteral.ScreenType and assigning the CurrentItem to it on the ICollectionView.CurrentChanged event, all work correctly.  My suspicion is the the second problem my have something to do with the absence of the IsSynchronizedWithCurrentItem property on the ComboBoxColumn.
    Thanks for your help,
    Steve
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Mar 2013 Link to this post

    Hello Steve,

    I am glad to hear that you have resolved the issue. Thank you for sharing the solution with the community.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready