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

How to bind PropertyGrid to GridView selectedItem in code?

6 Answers 542 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Markus
Top achievements
Rank 1
Markus asked on 07 Apr 2014, 02:55 PM
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

6 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 08 Apr 2014, 07:01 AM
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.

 
0
Yoan
Telerik team
answered on 08 Apr 2014, 09:01 AM
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.

 
0
Markus
Top achievements
Rank 1
answered on 09 Apr 2014, 08:27 AM
Hi Yoan,

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

Markus
0
Yoan
Telerik team
answered on 14 Apr 2014, 08:09 AM
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.

 
0
kiran
Top achievements
Rank 1
answered on 02 Sep 2017, 05:18 AM

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

0
Yoan
Telerik team
answered on 06 Sep 2017, 04:04 PM
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 you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PropertyGrid
Asked by
Markus
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Markus
Top achievements
Rank 1
kiran
Top achievements
Rank 1
Share this question
or