I have been using the property grid and I like it a lot, but now i have problem. Is there a way to add "properties" at runtime?
I have been trying to get a datatable/datarow to work with the property grid with no luck.
Any ideas?
Axel
5 Answers, 1 is accepted
Since RadPropertyGrid's PropertyDefinitions property is of type PropertyDefinitionCollection, which inherits from ObservableCollection<PropertyDefinition>, the control is aware of all the collection changes you are applying at runtime. I have prepared a very simple project that illustrates this. However, if you experience any specific problems with your scenario, feel free to send us you project, in order to debug it for you.
Kind regards,
Ivan Ivanov
the Telerik team
I have a class that contains a dictionary object. How would I bind the propertygrid to display each kevalue pair as a property in the grid. the data class looks like this
public
class
SubjectData
{
public
Dictionary<
string
,
object
> Attributes {
get
;
set
; }
public
SubjectData()
{
Attributes =
new
Dictionary<
string
,
object
>();
Attributes.Add(
"MyProp"
,
"1234abc"
);
Attributes.Add(
"MyProp2"
, 12345);
Attributes.Add(
"MyProp3"
,
true
);
}
}
And this is where I create the properties and add it to the grid
public
MainWindow()
{
InitializeComponent();
radPropertyGrid.Item =
new
SubjectData();
PropertyDefinition p =
new
PropertyDefinition();
p.Binding =
new
Binding(
"Attributes"
);
p.DisplayName =
"Property 1"
;
radPropertyGrid.PropertyDefinitions.Add(p);
}
I expect to see the property name and a textbox with the value as specified in the Dictionary.
Please help
Dolf
Setting just the Binding property of the added PropertyDefinitions won't work properly here. You should define your own editor templates that have appropriate bindings set. I would advise you to bind them to the "Attributes" property and use a converter, passing the respective key as a converter parameter.
Best wishes,
Ivan Ivanov
the Telerik team
Hi Ivan, I am struggling to get there as well. I need to populate the fields that come from a SQL query at runtime. I don't have any problem creating the XAML, as this is a trivial task. My issue is with the ViewModel (I'm using MVVM).
These are the choices that have tested unsucessfully:
1. Expando objects: work fine but cannot create from XML
2. DataRow: this is the closest match since it would be straigthforward but it doesn't show initial values, however it saves them, so its 50% of the solution
3. Dictionary: tried to follow your advise on that, but I have no clue (any snippet perhaps?)
4. Plain XML: as before with expando test, it works with XAML, which is great but how can I map that properties with XML as datasource? again totally nuts...
Any tip, help, link, thought, would be highly appreciated.
Thanks!
Mauricio
Dynamic Code Generation
Thanks.