How to bind PropertyGrid to GridView selectedItem in code?

7 posts, 0 answers
  1. Markus
    Markus avatar
    12 posts
    Member since:
    Nov 2013

    Posted 07 Apr 2014 Link to this post

    I have a GridView and a PropertyGrid both created in code not XAML.
    Now I try to bind the selected item of the GridView to the PropertyGrid also via code and not XAML.
    I tried something like this:

    Binding propGridBinding = new Binding("SelectedItem");
    propGridBinding.ElementName = "myTreeListView";   // assuming this is the name of the GridView
    propertyGrid.Item = propGridBinding;

    But when I try to run this code I get an error message like this:
    An unhandled exception of type 'System.NotSupportedException' occurred in System.dll
    Additional information: 'CultureInfoIetfLanguageTagConverter' is unable to convert '(null)' to 'System.String'.

    I even get the same type of error if I just try to bind the PropertyGrid to a visual element to be able to view and edit its properties.

    I must be missing something.

    Any help is very much appreciated.

    Thanks,
    Markus
  2. Yoan
    Admin
    Yoan avatar
    1124 posts

    Posted 08 Apr 2014 Link to this post

    Hi Markus,

    You can set PropertyGrid's Item to be the SelectedItem of RadGridView in its SelectionChanged event. Please check the following code snippet for a reference:
               RadPropertyGrid myPropertyGrid;
            RadGridView myGridView;
            public MainWindow()
            {
                InitializeComponent();
     
                myGridView = new RadGridView();
                myGridView.ItemsSource = Club.GetClubs();
     
                myGridView.IsSynchronizedWithCurrentItem = true;
                myGridView.SelectionChanged += myGridView_SelectionChanged;
     
                myPropertyGrid = new RadPropertyGrid();
                myPropertyGrid.Item = myGridView.SelectedItem;
            }
     
            void myGridView_SelectionChanged(object sender, SelectionChangeEventArgs e)
            {
                myPropertyGrid.Item = myGridView.SelectedItem;
            }

    I hope this helps.

    Regards,
    Yoan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Yoan
    Admin
    Yoan avatar
    1124 posts

    Posted 08 Apr 2014 Link to this post

    Hi Markus,

    Just a quick follow-up - you can bind PropertyGrid's Item to GridView's SelectedItem in code-behind like so:

    Binding binding = new Binding("SelectedItem") { ElementName = "myGridView" };
    this.myPropertyGrid.SetBinding(RadPropertyGrid.ItemProperty, binding);


    Regards,
    Yoan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  4. Markus
    Markus avatar
    12 posts
    Member since:
    Nov 2013

    Posted 09 Apr 2014 Link to this post

    Hi Yoan,

    thanks for your answers. I'll give them a try soon and let you know how it works.

    Markus
  5. Yoan
    Admin
    Yoan avatar
    1124 posts

    Posted 14 Apr 2014 Link to this post

    Hello Markus,

    Please give it a try and let me know if you need further assistance on this.

    Regards,
    Yoan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. kiran
    kiran avatar
    3 posts
    Member since:
    Jul 2017

    Posted 02 Sep in reply to Yoan Link to this post

    Hi Yoan,

    I just have the same issue , I am generating rad grid view dynamically and want to set GridView's SelectedItem as my SelectedCustomer Property so I just tried 

     Binding binding = new Binding("SelectedItem") { ElementName = "radGridView" };
                radGridView.SetBinding(RadPropertyGrid.ItemProperty, binding);

    from modelview( I m nothing doing in .xaml file every thing I have to code from viewmodel)

    And tried to get value inside 

     public DynamicEntity SelectedCustomer
            {
                get { return _selectedCustomer; }
                set { _selectedCustomer = value; OnPropertyChanged("SelectedCustomer"); } //HERE I JUST SET BREAK POINT ON SELECTION OF GRID VIEW ROW BUT NOTHING IS  CHANGE.
            }

    Then I just tried radGridView.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(myGridView_SelectionChanged); it works fine but as in mvvm pattern , it's better to not bind any events with mvvm so can you tell how to resolve it , we are still trying telerik control and we are on poc base.....

  7. Yoan
    Admin
    Yoan avatar
    1124 posts

    Posted 06 Sep Link to this post

    Hi,

    I am sending you a sample project which demonstrates how to achieve the desired behavior. Basically, I am binding GridView's SelectedItem property to a SelectedItem property of my ViewModel, then the PropertyGrid's Item property is bound to ViewModel's SelectedItem property and everything works as expected.

    I hope this helps.

    Regards,
    Yoan
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top