How to bind PropertyGrid to GridView selectedItem in code?

5 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
    1070 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. UI for WPF is Visual Studio 2017 Ready
  4. Yoan
    Admin
    Yoan avatar
    1070 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.

     
  5. 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
  6. Yoan
    Admin
    Yoan avatar
    1070 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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready